mako\cache\XCache


Description


XCache adapter.


Class methods


Toggle source

public __construct($config)


Constructor.


Parameters

Type Description
array Configuration
Return value

NULL

public function __construct(array $config)
{
	parent::__construct($config['identifier']);
	
	$this->username = $config['username'];
	
	$this->password = $config['password'];
	
	if(function_exists('xcache_get') === false)
	{
		throw new RuntimeException(vsprintf("%s(): XCache is not available.", array(__METHOD__)));
	}
}

Toggle source

public write($key, $value, $ttl = 0)


Store variable in the cache.


Parameters

Type Description
string Cache key
mixed The variable to store
int (optional) Time to live
Return value

boolean

public function write($key, $value, $ttl = 0)
{
	return xcache_set("{$this->identifier}_{$key}", serialize($value), $ttl);
}

Toggle source

public read($key)


Fetch variable from the cache.


Parameters

Type Description
string Cache key
Return value

mixed

public function read($key)
{
	return unserialize(xcache_get("{$this->identifier}_{$key}"));
}

Toggle source

public delete($key)


Delete a variable from the cache.


Parameters

Type Description
string Cache key
Return value

boolean

public function delete($key)
{
	return xcache_unset("{$this->identifier}_{$key}");
}

Toggle source

public clear()


Clears the user cache.

Return value

boolean

public function clear()
{
	$cleared = true;

	// Set XCache password

	$tempUsername = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : false;
	$tempPassword = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : false;

	$_SERVER['PHP_AUTH_USER'] = $this->username;
	$_SERVER['PHP_AUTH_PW']   = $this->password;

	// Clear Cache

	$cacheCount = xcache_count(XC_TYPE_VAR);

	for($i = 0; $i < $cacheCount; $i++)
	{
		if(@xcache_clear_cache(XC_TYPE_VAR, $i) === false)
		{
			$cleared = false;
			break;
		}
	}

	// Reset PHP_AUTH username/password

	if($tempUsername !== false)
	{
		$_SERVER['PHP_AUTH_USER'] = $tempUsername;
	}
	else
	{
		unset($_SERVER['PHP_AUTH_USER']);
	}

	if($tempPassword !== false)
	{
		$_SERVER['PHP_AUTH_PW'] = $tempPassword;
	}
	else
	{
		unset($_SERVER['PHP_AUTH_PW']);
	}

	// Return result

	return $cleared;
}

final public remember($key, $closure, $ttl = 0)


Fetches variable from cache and stores it if it doesn't exist.


Parameters

Type Description
string Cache key
closure Closure (anonymous function) that returns value to store if it doesn't already exist
int (optional) Time to live
Return value

mixed


final public __set($key, $value)


Magic setter.


Parameters

Type Description
string Cache key
mixed The variable to store
Return value

NULL


final public __get($key)


Magic getter.


Parameters

Type Description
string Cache key
Return value

mixed


final public __isset($key)


Magic isset.


Parameters

Type Description
string Cache key
Return value

boolean


final public __unset($key)


Magic unsetter.


Parameters

Type Description
string Cache key
Return value

NULL