includes/acm/acm_xcache.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/acm/acm_xcache.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,121 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package acm
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005, 2009 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +* @ignore
    1.16 +*/
    1.17 +if (!defined('IN_PHPBB'))
    1.18 +{
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +// Include the abstract base
    1.23 +if (!class_exists('acm_memory'))
    1.24 +{
    1.25 +	require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx");
    1.26 +}
    1.27 +
    1.28 +/**
    1.29 +* ACM for XCache
    1.30 +* @package acm
    1.31 +*
    1.32 +* To use this module you need ini_get() enabled and the following INI settings configured as follows:
    1.33 +* - xcache.var_size > 0
    1.34 +* - xcache.admin.enable_auth = off (or xcache.admin.user and xcache.admin.password set)
    1.35 +*
    1.36 +*/
    1.37 +class acm extends acm_memory
    1.38 +{
    1.39 +	var $extension = 'XCache';
    1.40 +
    1.41 +	function acm()
    1.42 +	{
    1.43 +		parent::acm_memory();
    1.44 +
    1.45 +		if (!function_exists('ini_get') || (int) ini_get('xcache.var_size') <= 0)
    1.46 +		{
    1.47 +			trigger_error('Increase xcache.var_size setting above 0 or enable ini_get() to use this ACM module.', E_USER_ERROR);
    1.48 +		}
    1.49 +	}
    1.50 +
    1.51 +	/**
    1.52 +	* Purge cache data
    1.53 +	*
    1.54 +	* @return void
    1.55 +	*/
    1.56 +	function purge()
    1.57 +	{
    1.58 +		// Run before for XCache, if admin functions are disabled it will terminate execution
    1.59 +		parent::purge();
    1.60 +
    1.61 +		// If the admin authentication is enabled but not set up, this will cause a nasty error.
    1.62 +		// Not much we can do about it though.
    1.63 +		$n = xcache_count(XC_TYPE_VAR);
    1.64 +
    1.65 +		for ($i = 0; $i < $n; $i++)
    1.66 +		{
    1.67 +			xcache_clear_cache(XC_TYPE_VAR, $i);
    1.68 +		}
    1.69 +	}
    1.70 +
    1.71 +	/**
    1.72 +	* Fetch an item from the cache
    1.73 +	*
    1.74 +	* @access protected
    1.75 +	* @param string $var Cache key
    1.76 +	* @return mixed Cached data
    1.77 +	*/
    1.78 +	function _read($var)
    1.79 +	{
    1.80 +		$result = xcache_get($this->key_prefix . $var);
    1.81 +
    1.82 +		return ($result !== null) ? $result : false;
    1.83 +	}
    1.84 +
    1.85 +	/**
    1.86 +	* Store data in the cache
    1.87 +	*
    1.88 +	* @access protected
    1.89 +	* @param string $var Cache key
    1.90 +	* @param mixed $data Data to store
    1.91 +	* @param int $ttl Time-to-live of cached data
    1.92 +	* @return bool True if the operation succeeded
    1.93 +	*/
    1.94 +	function _write($var, $data, $ttl = 2592000)
    1.95 +	{
    1.96 +		return xcache_set($this->key_prefix . $var, $data, $ttl);
    1.97 +	}
    1.98 +
    1.99 +	/**
   1.100 +	* Remove an item from the cache
   1.101 +	*
   1.102 +	* @access protected
   1.103 +	* @param string $var Cache key
   1.104 +	* @return bool True if the operation succeeded
   1.105 +	*/
   1.106 +	function _delete($var)
   1.107 +	{
   1.108 +		return xcache_unset($this->key_prefix . $var);
   1.109 +	}
   1.110 +
   1.111 +	/**
   1.112 +	* Check if a cache var exists
   1.113 +	*
   1.114 +	* @access protected
   1.115 +	* @param string $var Cache key
   1.116 +	* @return bool True if it exists, otherwise false
   1.117 +	*/	
   1.118 +	function _isset($var)
   1.119 +	{
   1.120 +		return xcache_isset($this->key_prefix . $var);
   1.121 +	}
   1.122 +}
   1.123 +
   1.124 +?>
   1.125 \ No newline at end of file