DummyCache.php 2.58 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
{
	/**
	 * Retrieves a value from cache with a specified key.
25 26
	 * This is the implementation of the method declared in the parent class.
	 * @param string $key a unique key identifying the cached value
27
	 * @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
Qiang Xue committed
28
	 */
29
	protected function getValue($key)
Qiang Xue committed
30 31 32 33 34
	{
		return false;
	}

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

	/**
	 * Stores a value identified by a key into cache if the cache does not contain this key.
50 51 52
	 * 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
53 54 55
	 * @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
	 */
56
	protected function addValue($key, $value, $expire)
Qiang Xue committed
57 58 59 60 61 62
	{
		return true;
	}

	/**
	 * Deletes a value with the specified key from cache
63 64
	 * 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
65 66
	 * @return boolean if no error happens during deletion
	 */
67
	protected function deleteValue($key)
Qiang Xue committed
68 69 70 71 72 73
	{
		return true;
	}

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