DummyCache.php 2.76 KB
Newer Older
Qiang Xue committed
1 2 3
<?php
/**
 * @link http://www.yiiframework.com/
Qiang Xue committed
4
 * @copyright Copyright (c) 2008 Yii Software LLC
Qiang Xue committed
5 6 7
 * @license http://www.yiiframework.com/license/
 */

Qiang Xue committed
8 9
namespace yii\caching;

Qiang Xue committed
10
/**
11
 * DummyCache is a placeholder cache component.
Qiang Xue committed
12
 *
13
 * DummyCache does not cache anything. It is provided so that one can always configure
Qiang Xue committed
14
 * a 'cache' application component and save the check of existence of `\Yii::$app->cache`.
15
 * By replacing DummyCache with some other cache component, one can quickly switch from
Qiang Xue committed
16 17 18
 * non-caching mode to caching mode.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
Qiang Xue committed
19
 * @since 2.0
Qiang Xue committed
20
 */
21
class DummyCache extends Cache
Qiang Xue committed
22
{
23 24 25
    /**
     * Retrieves a value from cache with a specified key.
     * This is the implementation of the method declared in the parent class.
26
     * @param string $key a unique key identifying the cached value
27 28 29 30 31 32
     * @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
     */
    protected function getValue($key)
    {
        return false;
    }
Qiang Xue committed
33

34 35 36 37
    /**
     * Stores a value identified by a key in cache.
     * This is the implementation of the method declared in the parent class.
     *
38 39 40
     * @param string $key the key identifying the value to be cached
     * @param string $value the value to be cached
     * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
41 42
     * @return boolean true if the value is successfully stored into cache, false otherwise
     */
Qiang Xue committed
43
    protected function setValue($key, $value, $duration)
44 45 46
    {
        return true;
    }
Qiang Xue committed
47

48 49 50
    /**
     * 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.
51 52 53
     * @param string $key the key identifying the value to be cached
     * @param string $value the value to be cached
     * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
54 55
     * @return boolean true if the value is successfully stored into cache, false otherwise
     */
Qiang Xue committed
56
    protected function addValue($key, $value, $duration)
57 58 59
    {
        return true;
    }
Qiang Xue committed
60

61 62 63
    /**
     * Deletes a value with the specified key from cache
     * This is the implementation of the method declared in the parent class.
64
     * @param string $key the key of the value to be deleted
65 66 67 68 69 70
     * @return boolean if no error happens during deletion
     */
    protected function deleteValue($key)
    {
        return true;
    }
Qiang Xue committed
71

72 73 74 75 76 77 78 79 80
    /**
     * Deletes all values from cache.
     * This is the implementation of the method declared in the parent class.
     * @return boolean whether the flush operation was successful.
     */
    protected function flushValues()
    {
        return true;
    }
Qiang Xue committed
81
}