Yii2 framework backup
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.2 KiB

13 years ago
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
13 years ago
* @license http://www.yiiframework.com/license/
*/
namespace yii\caching;
13 years ago
/**
* XCache provides XCache caching in terms of an application component.
13 years ago
*
* To use this application component, the [XCache PHP extension](http://xcache.lighttpd.net/) must be loaded.
* Also note that the [[flush()]] functionality will work correctly only if "xcache.admin.enable_auth"
* is set to "Off" in php.ini.
13 years ago
*
* See [[Cache]] for common cache operations that XCache supports.
13 years ago
*
* For more details and usage information on Cache, see the [guide article on caching](guide:caching-overview).
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @deprecated since 2.0.14. This class will be removed in 2.1.0.
13 years ago
*/
class XCache extends Cache
13 years ago
{
/**
* Checks whether a specified key exists in the cache.
* This can be faster than getting the value from the cache if the data is big.
* Note that this method does not check whether the dependency associated
* with the cached data, if there is any, has changed. So a call to [[get]]
* may return false while exists returns true.
* @param mixed $key a key identifying the cached value. This can be a simple string or
* a complex data structure consisting of factors representing the key.
* @return bool true if a value exists in cache, false if the value is not in the cache or expired.
*/
public function exists($key)
{
$key = $this->buildKey($key);
return xcache_isset($key);
}
13 years ago
/**
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
* @param string $key a unique key identifying the cached value
* @return mixed|false the value stored in cache, false if the value is not in the cache or expired.
*/
protected function getValue($key)
{
return xcache_isset($key) ? xcache_get($key) : false;
}
13 years ago
/**
* Stores a value identified by a key in cache.
* This is the implementation of the method declared in the parent class.
*
* @param string $key the key identifying the value to be cached
* @param mixed $value the value to be cached. Most often it's a string. If you have disabled [[serializer]],
* it could be something else.
* @param int $duration the number of seconds in which the cached value will expire. 0 means never expire.
* @return bool true if the value is successfully stored into cache, false otherwise
*/
11 years ago
protected function setValue($key, $value, $duration)
{
11 years ago
return xcache_set($key, $value, $duration);
}
13 years ago
/**
* Stores a value identified by a key into cache if the cache does not contain this key.
* This is the implementation of the method declared in the parent class.
*
* @param string $key the key identifying the value to be cached
* @param mixed $value the value to be cached. Most often it's a string. If you have disabled [[serializer]],
* it could be something else.
* @param int $duration the number of seconds in which the cached value will expire. 0 means never expire.
* @return bool true if the value is successfully stored into cache, false otherwise
*/
11 years ago
protected function addValue($key, $value, $duration)
{
11 years ago
return !xcache_isset($key) ? $this->setValue($key, $value, $duration) : false;
}
13 years ago
/**
* Deletes a value with the specified key from cache
* This is the implementation of the method declared in the parent class.
* @param string $key the key of the value to be deleted
* @return bool if no error happens during deletion
*/
protected function deleteValue($key)
{
return xcache_unset($key);
}
/**
* Deletes all values from cache.
* This is the implementation of the method declared in the parent class.
* @return bool whether the flush operation was successful.
*/
protected function flushValues()
{
for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++) {
if (xcache_clear_cache(XC_TYPE_VAR, $i) === false) {
return false;
}
}
return true;
}
13 years ago
}