DummyCache.php 2.61 KB
Newer Older
Qiang Xue committed
1 2
<?php
/**
3
 * DummyCache class file.
Qiang Xue committed
4 5
 *
 * @link http://www.yiiframework.com/
Qiang Xue committed
6
 * @copyright Copyright &copy; 2008 Yii Software LLC
Qiang Xue committed
7 8 9
 * @license http://www.yiiframework.com/license/
 */

Qiang Xue committed
10 11
namespace yii\caching;

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

	/**
37 38
	 * Stores a value identified by a key in cache.
	 * This is the implementation of the method declared in the parent class.
Qiang Xue committed
39
	 *
40 41
	 * @param string $key the key identifying the value to be cached
	 * @param string $value the value to be cached
Qiang Xue committed
42 43 44
	 * @param integer $expire 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
	 */
45
	protected function setValue($key, $value, $expire)
Qiang Xue committed
46 47 48 49 50 51
	{
		return true;
	}

	/**
	 * Stores a value identified by a key into cache if the cache does not contain this key.
52 53 54
	 * This is the implementation of the method declared in the parent class.
	 * @param string $key the key identifying the value to be cached
	 * @param string $value the value to be cached
Qiang Xue committed
55 56 57
	 * @param integer $expire 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
	 */
58
	protected function addValue($key, $value, $expire)
Qiang Xue committed
59 60 61 62 63 64
	{
		return true;
	}

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

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