XCache adapter.
Constructor.
| Type | Description |
|---|---|
| array | Configuration |
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__)));
}
}
Store variable in the cache.
| Type | Description |
|---|---|
| string | Cache key |
| mixed | The variable to store |
| int | (optional) Time to live |
boolean
public function write($key, $value, $ttl = 0)
{
return xcache_set("{$this->identifier}_{$key}", serialize($value), $ttl);
}
Fetch variable from the cache.
| Type | Description |
|---|---|
| string | Cache key |
mixed
public function read($key)
{
return unserialize(xcache_get("{$this->identifier}_{$key}"));
}
Delete a variable from the cache.
| Type | Description |
|---|---|
| string | Cache key |
boolean
public function delete($key)
{
return xcache_unset("{$this->identifier}_{$key}");
}
Clears the user cache.
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;
}
Fetches variable from cache and stores it if it doesn't exist.
| 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 |
mixed
Magic setter.
| Type | Description |
|---|---|
| string | Cache key |
| mixed | The variable to store |
NULL
Magic getter.
| Type | Description |
|---|---|
| string | Cache key |
mixed
Magic isset.
| Type | Description |
|---|---|
| string | Cache key |
boolean
Magic unsetter.
| Type | Description |
|---|---|
| string | Cache key |
NULL