3
* CZendDataCache class file
5
* @author Steffen Dietz <steffo.dietz[at]googlemail[dot]com>
6
* @link http://www.yiiframework.com/
7
* @copyright Copyright © 2008-2011 Yii Software LLC
8
* @license http://www.yiiframework.com/license/
12
* CZendDataCache implements a cache application module based on the Zend Data Cache
13
* delivered with {@link http://www.zend.com/en/products/server/ ZendServer}.
15
* To use this application component, the Zend Data Cache PHP extension must be loaded.
17
* See {@link CCache} manual for common cache operations that are supported by CZendDataCache.
19
* @author Steffen Dietz <steffo.dietz[at]googlemail[dot]com>
20
* @version $Id: CZendDataCache.php 2799 2011-01-01 19:31:13Z qiang.xue $
21
* @package system.caching
24
class CZendDataCache extends CCache
27
* Initializes this application component.
28
* This method is required by the {@link IApplicationComponent} interface.
29
* It checks the availability of Zend Data Cache.
30
* @throws CException if Zend Data Cache extension is not loaded.
32
public function init()
35
if(!function_exists('zend_shm_cache_store'))
36
throw new CException(Yii::t('yii','CZendDataCache requires PHP Zend Data Cache extension to be loaded.'));
40
* Retrieves a value from cache with a specified key.
41
* This is the implementation of the method declared in the parent class.
42
* @param string $key a unique key identifying the cached value
43
* @return string the value stored in cache, false if the value is not in the cache or expired.
45
protected function getValue($key)
47
$result = zend_shm_cache_fetch($key);
48
return $result !== NULL ? $result : false;
52
* Stores a value identified by a key in cache.
53
* This is the implementation of the method declared in the parent class.
55
* @param string $key the key identifying the value to be cached
56
* @param string $value the value to be cached
57
* @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
58
* @return boolean true if the value is successfully stored into cache, false otherwise
60
protected function setValue($key,$value,$expire)
62
return zend_shm_cache_store($key,$value,$expire);
66
* Stores a value identified by a key into cache if the cache does not contain this key.
67
* This is the implementation of the method declared in the parent class.
69
* @param string $key the key identifying the value to be cached
70
* @param string $value the value to be cached
71
* @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
72
* @return boolean true if the value is successfully stored into cache, false otherwise
74
protected function addValue($key,$value,$expire)
76
return (NULL === zend_shm_cache_fetch($key)) ? $this->setValue($key,$value,$expire) : false;
80
* Deletes a value with the specified key from cache
81
* This is the implementation of the method declared in the parent class.
82
* @param string $key the key of the value to be deleted
83
* @return boolean if no error happens during deletion
85
protected function deleteValue($key)
87
return zend_shm_cache_delete($key);
91
* Deletes all values from cache.
92
* This is the implementation of the method declared in the parent class.
93
* @return boolean whether the flush operation was successful.
96
protected function flushValues()
98
return zend_shm_cache_clear();