1: <?php
2: /**
3: * CWinCache class file
4: *
5: * @author Alexander Makarov <sam@rmcreative.ru>
6: * @link http://www.yiiframework.com/
7: * @copyright 2008-2013 Yii Software LLC
8: * @license http://www.yiiframework.com/license/
9: */
10:
11: /**
12: * CWinCache implements a cache application component based on {@link http://www.iis.net/expand/wincacheforphp WinCache}.
13: *
14: * To use this application component, the WinCache PHP extension must be loaded.
15: *
16: * See {@link CCache} manual for common cache operations that are supported by CWinCache.
17: *
18: * @author Alexander Makarov <sam@rmcreative.ru>
19: * @package system.caching
20: * @since 1.1.2
21: */
22: class CWinCache extends CCache {
23: /**
24: * Initializes this application component.
25: * This method is required by the {@link IApplicationComponent} interface.
26: * It checks the availability of WinCache extension and WinCache user cache.
27: * @throws CException if WinCache extension is not loaded or user cache is disabled
28: */
29: public function init()
30: {
31: parent::init();
32: if(!extension_loaded('wincache'))
33: throw new CException(Yii::t('yii', 'CWinCache requires PHP wincache extension to be loaded.'));
34: if(!ini_get('wincache.ucenabled'))
35: throw new CException(Yii::t('yii', 'CWinCache user cache is disabled. Please set wincache.ucenabled to On in your php.ini.'));
36: }
37:
38: /**
39: * Retrieves a value from cache with a specified key.
40: * This is the implementation of the method declared in the parent class.
41: * @param string $key a unique key identifying the cached value
42: * @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
43: */
44: protected function getValue($key)
45: {
46: return wincache_ucache_get($key);
47: }
48:
49: /**
50: * Retrieves multiple values from cache with the specified keys.
51: * @param array $keys a list of keys identifying the cached values
52: * @return array a list of cached values indexed by the keys
53: */
54: protected function getValues($keys)
55: {
56: return wincache_ucache_get($keys);
57: }
58:
59: /**
60: * Stores a value identified by a key in cache.
61: * This is the implementation of the method declared in the parent class.
62: *
63: * @param string $key the key identifying the value to be cached
64: * @param string $value the value to be cached
65: * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
66: * @return boolean true if the value is successfully stored into cache, false otherwise
67: */
68: protected function setValue($key,$value,$expire)
69: {
70: return wincache_ucache_set($key,$value,$expire);
71: }
72:
73: /**
74: * Stores a value identified by a key into cache if the cache does not contain this key.
75: * This is the implementation of the method declared in the parent class.
76: *
77: * @param string $key the key identifying the value to be cached
78: * @param string $value the value to be cached
79: * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
80: * @return boolean true if the value is successfully stored into cache, false otherwise
81: */
82: protected function addValue($key,$value,$expire)
83: {
84: return wincache_ucache_add($key,$value,$expire);
85: }
86:
87: /**
88: * Deletes a value with the specified key from cache
89: * This is the implementation of the method declared in the parent class.
90: * @param string $key the key of the value to be deleted
91: * @return boolean if no error happens during deletion
92: */
93: protected function deleteValue($key)
94: {
95: return wincache_ucache_delete($key);
96: }
97:
98: /**
99: * Deletes all values from cache.
100: * This is the implementation of the method declared in the parent class.
101: * @return boolean whether the flush operation was successful.
102: * @since 1.1.5
103: */
104: protected function flushValues()
105: {
106: return wincache_ucache_clear();
107: }
108: }