Kohana Cache Xcache Driver
Requires Xcache http://xcache.lighttpd.net/
Class declared in MODPATH/cache/classes/kohana/cache/xcache.php on line 14.
integer 3600
string
$defaultdefault driver to use
string(4) "file"
Kohana_Cache
$instancesinstances
array(0)
Config
$_configDelete a cache entry based on id
string
$id
required - Idboolean
public function delete($id)
{
return xcache_unset($this->_sanitize_id($id));
}
Delete all cache entries To use this method xcache.admin.enable_auth has to be Off in xcache.ini
void
public function delete_all()
{
xcache_clear_cache(XC_TYPE_PHP, 0);
}
Retrieve a value based on an id
string
$id
required - Idstring
$default
= NULL - Default [Optional] Default value to return if id not foundmixed
public function get($id, $default = NULL)
{
return (($data = xcache_get($this->_sanitize_id($id))) === NULL) ? $default : $data;
}
Set a value based on an id. Optionally add tags.
string
$id
required - Idstring
$data
required - Datainteger
$lifetime
= NULL - Lifetime [Optional]boolean
public function set($id, $data, $lifetime = NULL)
{
if (NULL === $lifetime)
{
$lifetime = Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE);
}
return xcache_set($this->_sanitize_id($id), $data, $lifetime);
}
Overload the __clone() method to prevent cloning
void
public function __clone()
{
throw new Kohana_Cache_Exception('Cloning of Kohana_Cache objects is forbidden');
}
Creates a singleton of a Kohana Cache group. If no group is supplied the default cache group is used.
// Create an instance of the default group
$default_group = Cache::instance();
// Create an instance of a group
$foo_group = Cache::instance('foo');
// Access an instantiated group directly
$foo_group = Cache::$instances['default'];
string
$group
= NULL - The name of the cache group to use [Optional]Cache
public static function instance($group = NULL)
{
// If there is no group supplied
if ($group === NULL)
{
// Use the default setting
$group = Cache::$default;
}
if (isset(Cache::$instances[$group]))
{
// Return the current group if initiated already
return Cache::$instances[$group];
}
$config = Kohana::config('cache');
if ( ! $config->offsetExists($group))
{
throw new Kohana_Cache_Exception('Failed to load Kohana Cache group: :group', array(':group' => $group));
}
$config = $config->get($group);
// Create a new cache type instance
$cache_class = 'Cache_'.ucfirst($config['driver']);
Cache::$instances[$group] = new $cache_class($config);
// Return the instance
return Cache::$instances[$group];
}
Check for existence of the APC extension
array
$config
required - Configurationprotected function __construct(array $config)
{
if ( ! extension_loaded('xcache'))
{
throw new Kohana_Cache_Exception('PHP Xcache extension is not available.');
}
parent::__construct($config);
}
Replaces troublesome characters with underscores.
// Sanitize a cache id
$id = $this->_sanitize_id($id);
string
$id
required - Id of cache to sanitizestring
protected function _sanitize_id($id)
{
// Change slashes and spaces to underscores
return str_replace(array('/', '\\', ' '), '_', $id);
}