Modules

Kohana_Cache_Xcache
extends Cache
extends Kohana_Cache

Kohana Cache Xcache Driver

Requires Xcache http://xcache.lighttpd.net/

package
Kohana
category
Cache
author
Kohana Team
copyright
© 2009-2012 Kohana Team
license
http://kohanaphp.com/license

Class declared in MODPATH/cache/classes/kohana/cache/xcache.php on line 14.

Constants

DEFAULT_EXPIRE

integer 3600

Properties

public static string $default

default driver to use

string(4) "file"

public static Kohana_Cache $instances

instances

array(0) 

protected Config $_config

Methods

public delete( string $id ) (defined in Kohana_Cache_Xcache)

Delete a cache entry based on id

Parameters

  • string $id required - Id

Return Values

  • boolean

Source Code

public function delete($id)
{
	return xcache_unset($this->_sanitize_id($id));
}

public delete_all( ) (defined in Kohana_Cache_Xcache)

Delete all cache entries To use this method xcache.admin.enable_auth has to be Off in xcache.ini

Return Values

  • void

Source Code

public function delete_all()
{
	xcache_clear_cache(XC_TYPE_PHP, 0);
}

public get( string $id [, string $default = NULL ] ) (defined in Kohana_Cache_Xcache)

Retrieve a value based on an id

Parameters

  • string $id required - Id
  • string $default = NULL - Default [Optional] Default value to return if id not found

Return Values

  • mixed

Source Code

public function get($id, $default = NULL)
{
	return (($data = xcache_get($this->_sanitize_id($id))) === NULL) ? $default : $data;
}

public set( string $id , string $data [, integer $lifetime = NULL ] ) (defined in Kohana_Cache_Xcache)

Set a value based on an id. Optionally add tags.

Parameters

  • string $id required - Id
  • string $data required - Data
  • integer $lifetime = NULL - Lifetime [Optional]

Return Values

  • boolean

Source Code

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);
}

public __clone( ) (defined in Kohana_Cache)

Overload the __clone() method to prevent cloning

Tags

Return Values

  • void

Source Code

public function __clone()
{
	throw new Kohana_Cache_Exception('Cloning of Kohana_Cache objects is forbidden');
}

public static instance( [ string $group = NULL ] ) (defined in Kohana_Cache)

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'];

Parameters

  • string $group = NULL - The name of the cache group to use [Optional]

Tags

Return Values

  • Cache

Source Code

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];
}

protected __construct( array $config ) (defined in Kohana_Cache_Xcache)

Check for existence of the APC extension

Parameters

  • array $config required - Configuration

Tags

Source Code

protected function __construct(array $config)
{
	if ( ! extension_loaded('xcache'))
	{
		throw new Kohana_Cache_Exception('PHP Xcache extension is not available.');
	}

	parent::__construct($config);
}

protected _sanitize_id( string $id ) (defined in Kohana_Cache)

Replaces troublesome characters with underscores.

// Sanitize a cache id
$id = $this->_sanitize_id($id);

Parameters

  • string $id required - Id of cache to sanitize

Return Values

  • string

Source Code

protected function _sanitize_id($id)
{
	// Change slashes and spaces to underscores
	return str_replace(array('/', '\\', ' '), '_', $id);
}