CApcCache
CApcCache provides APC caching in terms of an application component.
The caching is based on
APC. To use this application component, the APC PHP extension must be loaded.
See
CCache manual for common cache operations that are supported by CApcCache.
Public Properties
Property |
Type |
Description |
Defined By |
behaviors | array | the behaviors that should be attached to this component. | CApplicationComponent |
hashKey | boolean | whether to md5-hash the cache key for normalization purposes. | CCache |
isInitialized | boolean | Checks if this application component has been initialized. | CApplicationComponent |
keyPrefix | string | a string prefixed to every cache key so that it is unique. | CCache |
serializer | array|boolean | the functions used to serialize and unserialize cached data. | CCache |
useApcu | boolean | whether to use apcu or apc as the underlying caching extension. | CApcCache |
Protected Methods
Method |
Description |
Defined By |
addValue() | Stores a value identified by a key into cache if the cache does not contain this key. | CApcCache |
deleteValue() | Deletes a value with the specified key from cache | CApcCache |
flushValues() | Deletes all values from cache. | CApcCache |
generateUniqueKey() | | CCache |
getValue() | Retrieves a value from cache with a specified key. | CApcCache |
getValues() | Retrieves multiple values from cache with the specified keys. | CApcCache |
setValue() | Stores a value identified by a key in cache. | CApcCache |
Property Details
public boolean $useApcu;
whether to use apcu or apc as the underlying caching extension. If true apcu will be used. If false apc. will be used. Defaults to false.
Method Details
protected boolean addValue(string $key, string $value, integer $expire) |
$key | string | the key identifying the value to be cached |
$value | string | the value to be cached |
$expire | integer | the number of seconds in which the cached value will expire. 0 means never expire. |
{return} | boolean | true if the value is successfully stored into cache, false otherwise |
Source Code: framework/caching/CApcCache.php#94 (
show)
protected function addValue($key,$value,$expire)
{
return $this->useApcu ? apcu_add($key,$value,$expire) : apc_add($key,$value,$expire);
}
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.
protected boolean deleteValue(string $key) |
$key | string | the key of the value to be deleted |
{return} | boolean | if no error happens during deletion |
Deletes a value with the specified key from cache This is the implementation of the method declared in the parent class.
protected boolean flushValues() |
{return} | boolean | whether the flush operation was successful. |
Deletes all values from cache. This is the implementation of the method declared in the parent class.
protected string|boolean getValue(string $key) |
$key | string | a unique key identifying the cached value |
{return} | string|boolean | the value stored in cache, false if the value is not in the cache or expired. |
Retrieves a value from cache with a specified key. This is the implementation of the method declared in the parent class.
protected array getValues(array $keys) |
$keys | array | a list of keys identifying the cached values |
{return} | array | a list of cached values indexed by the keys |
Retrieves multiple values from cache with the specified keys.
Source Code: framework/caching/CApcCache.php#41 (
show)
public function init()
{
parent::init();
$extension=$this->useApcu ? 'apcu' : 'apc';
if(!extension_loaded($extension))
throw new CException(Yii::t('yii',"CApcCache requires PHP {extension} extension to be loaded.",
array('{extension}'=>$extension)));
}
Initializes this application component. This method is required by the IApplicationComponent interface. It checks the availability of APC.
protected boolean setValue(string $key, string $value, integer $expire) |
$key | string | the key identifying the value to be cached |
$value | string | the value to be cached |
$expire | integer | the number of seconds in which the cached value will expire. 0 means never expire. |
{return} | boolean | true if the value is successfully stored into cache, false otherwise |
Source Code: framework/caching/CApcCache.php#80 (
show)
protected function setValue($key,$value,$expire)
{
return $this->useApcu ? apcu_store($key,$value,$expire) : apc_store($key,$value,$expire);
}
Stores a value identified by a key in cache. This is the implementation of the method declared in the parent class.