includes/acm/acm_xcache.php
author indvdum (gotoindvdum[at]gmail[dot]com)
Sat, 10 Mar 2012 00:47:37 +0400
changeset 16 d6012dd9347f
parent 0 ceef6d64c21d
permissions -rw-r--r--
Removing old cubometry-style style
indvdum@0
     1
<?php
indvdum@0
     2
/**
indvdum@0
     3
*
indvdum@0
     4
* @package acm
indvdum@0
     5
* @version $Id$
indvdum@0
     6
* @copyright (c) 2005, 2009 phpBB Group
indvdum@0
     7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
indvdum@0
     8
*
indvdum@0
     9
*/
indvdum@0
    10
indvdum@0
    11
/**
indvdum@0
    12
* @ignore
indvdum@0
    13
*/
indvdum@0
    14
if (!defined('IN_PHPBB'))
indvdum@0
    15
{
indvdum@0
    16
	exit;
indvdum@0
    17
}
indvdum@0
    18
indvdum@0
    19
// Include the abstract base
indvdum@0
    20
if (!class_exists('acm_memory'))
indvdum@0
    21
{
indvdum@0
    22
	require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx");
indvdum@0
    23
}
indvdum@0
    24
indvdum@0
    25
/**
indvdum@0
    26
* ACM for XCache
indvdum@0
    27
* @package acm
indvdum@0
    28
*
indvdum@0
    29
* To use this module you need ini_get() enabled and the following INI settings configured as follows:
indvdum@0
    30
* - xcache.var_size > 0
indvdum@0
    31
* - xcache.admin.enable_auth = off (or xcache.admin.user and xcache.admin.password set)
indvdum@0
    32
*
indvdum@0
    33
*/
indvdum@0
    34
class acm extends acm_memory
indvdum@0
    35
{
indvdum@0
    36
	var $extension = 'XCache';
indvdum@0
    37
indvdum@0
    38
	function acm()
indvdum@0
    39
	{
indvdum@0
    40
		parent::acm_memory();
indvdum@0
    41
indvdum@0
    42
		if (!function_exists('ini_get') || (int) ini_get('xcache.var_size') <= 0)
indvdum@0
    43
		{
indvdum@0
    44
			trigger_error('Increase xcache.var_size setting above 0 or enable ini_get() to use this ACM module.', E_USER_ERROR);
indvdum@0
    45
		}
indvdum@0
    46
	}
indvdum@0
    47
indvdum@0
    48
	/**
indvdum@0
    49
	* Purge cache data
indvdum@0
    50
	*
indvdum@0
    51
	* @return void
indvdum@0
    52
	*/
indvdum@0
    53
	function purge()
indvdum@0
    54
	{
indvdum@0
    55
		// Run before for XCache, if admin functions are disabled it will terminate execution
indvdum@0
    56
		parent::purge();
indvdum@0
    57
indvdum@0
    58
		// If the admin authentication is enabled but not set up, this will cause a nasty error.
indvdum@0
    59
		// Not much we can do about it though.
indvdum@0
    60
		$n = xcache_count(XC_TYPE_VAR);
indvdum@0
    61
indvdum@0
    62
		for ($i = 0; $i < $n; $i++)
indvdum@0
    63
		{
indvdum@0
    64
			xcache_clear_cache(XC_TYPE_VAR, $i);
indvdum@0
    65
		}
indvdum@0
    66
	}
indvdum@0
    67
indvdum@0
    68
	/**
indvdum@0
    69
	* Fetch an item from the cache
indvdum@0
    70
	*
indvdum@0
    71
	* @access protected
indvdum@0
    72
	* @param string $var Cache key
indvdum@0
    73
	* @return mixed Cached data
indvdum@0
    74
	*/
indvdum@0
    75
	function _read($var)
indvdum@0
    76
	{
indvdum@0
    77
		$result = xcache_get($this->key_prefix . $var);
indvdum@0
    78
indvdum@0
    79
		return ($result !== null) ? $result : false;
indvdum@0
    80
	}
indvdum@0
    81
indvdum@0
    82
	/**
indvdum@0
    83
	* Store data in the cache
indvdum@0
    84
	*
indvdum@0
    85
	* @access protected
indvdum@0
    86
	* @param string $var Cache key
indvdum@0
    87
	* @param mixed $data Data to store
indvdum@0
    88
	* @param int $ttl Time-to-live of cached data
indvdum@0
    89
	* @return bool True if the operation succeeded
indvdum@0
    90
	*/
indvdum@0
    91
	function _write($var, $data, $ttl = 2592000)
indvdum@0
    92
	{
indvdum@0
    93
		return xcache_set($this->key_prefix . $var, $data, $ttl);
indvdum@0
    94
	}
indvdum@0
    95
indvdum@0
    96
	/**
indvdum@0
    97
	* Remove an item from the cache
indvdum@0
    98
	*
indvdum@0
    99
	* @access protected
indvdum@0
   100
	* @param string $var Cache key
indvdum@0
   101
	* @return bool True if the operation succeeded
indvdum@0
   102
	*/
indvdum@0
   103
	function _delete($var)
indvdum@0
   104
	{
indvdum@0
   105
		return xcache_unset($this->key_prefix . $var);
indvdum@0
   106
	}
indvdum@0
   107
indvdum@0
   108
	/**
indvdum@0
   109
	* Check if a cache var exists
indvdum@0
   110
	*
indvdum@0
   111
	* @access protected
indvdum@0
   112
	* @param string $var Cache key
indvdum@0
   113
	* @return bool True if it exists, otherwise false
indvdum@0
   114
	*/	
indvdum@0
   115
	function _isset($var)
indvdum@0
   116
	{
indvdum@0
   117
		return xcache_isset($this->key_prefix . $var);
indvdum@0
   118
	}
indvdum@0
   119
}
indvdum@0
   120
indvdum@0
   121
?>