~joebordes/chive/chive_lib_upgrade

« back to all changes in this revision

Viewing changes to yii/caching/CZendDataCache.php

  • Committer: Joe Bordes
  • Date: 2011-08-22 18:24:26 UTC
  • Revision ID: joe@tsolucio.com-20110822182426-zrvpiuyvm20ybjki
Update yii framework 1.1.8 and associated libraries.
Update About page to reflect changes.
Basic testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * CZendDataCache class file
 
4
 *
 
5
 * @author Steffen Dietz <steffo.dietz[at]googlemail[dot]com>
 
6
 * @link http://www.yiiframework.com/
 
7
 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
 
8
 * @license http://www.yiiframework.com/license/
 
9
 */
 
10
 
 
11
/**
 
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}.
 
14
 *
 
15
 * To use this application component, the Zend Data Cache PHP extension must be loaded.
 
16
 *
 
17
 * See {@link CCache} manual for common cache operations that are supported by CZendDataCache.
 
18
 *
 
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
 
22
 * @since 1.0.4
 
23
 */
 
24
class CZendDataCache extends CCache
 
25
{
 
26
        /**
 
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.
 
31
         */
 
32
        public function init()
 
33
        {
 
34
                parent::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.'));
 
37
        }
 
38
 
 
39
        /**
 
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.
 
44
         */
 
45
        protected function getValue($key)
 
46
        {
 
47
                $result = zend_shm_cache_fetch($key);
 
48
                return $result !== NULL ? $result : false;
 
49
        }
 
50
 
 
51
        /**
 
52
         * Stores a value identified by a key in cache.
 
53
         * This is the implementation of the method declared in the parent class.
 
54
         *
 
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
 
59
         */
 
60
        protected function setValue($key,$value,$expire)
 
61
        {
 
62
                return zend_shm_cache_store($key,$value,$expire);
 
63
        }
 
64
 
 
65
        /**
 
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.
 
68
         *
 
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
 
73
         */
 
74
        protected function addValue($key,$value,$expire)
 
75
        {
 
76
                return (NULL === zend_shm_cache_fetch($key)) ? $this->setValue($key,$value,$expire) : false;
 
77
        }
 
78
 
 
79
        /**
 
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
 
84
         */
 
85
        protected function deleteValue($key)
 
86
        {
 
87
                return zend_shm_cache_delete($key);
 
88
        }
 
89
 
 
90
        /**
 
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.
 
94
         * @since 1.1.5
 
95
         */
 
96
        protected function flushValues()
 
97
        {
 
98
                return zend_shm_cache_clear();
 
99
        }
 
100
}