7
* This source file is subject to the new BSD license that is bundled
8
* with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://framework.zend.com/license/new-bsd
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to license@zend.com so we can send you a copy immediately.
17
* @subpackage Zend_Cache_Backend
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
24
* @see Zend_Cache_Backend_Interface
26
require_once 'Zend/Cache/Backend/Interface.php';
29
* @see Zend_Cache_Backend
31
require_once 'Zend/Cache/Backend.php';
35
* @subpackage Zend_Cache_Backend
36
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
37
* @license http://framework.zend.com/license/new-bsd New BSD License
39
class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
44
* @var array available options
46
protected $_options = array();
49
* Frontend or Core directives
51
* @var array directives
53
protected $_directives = array();
56
* Array to log actions
60
private $_log = array();
63
* Current index for log array
72
* @param array $options associative array of options
75
public function __construct($options = array())
77
$this->_addLog('construct', array($options));
81
* Set the frontend directives
83
* @param array $directives assoc of directives
86
public function setDirectives($directives)
88
$this->_addLog('setDirectives', array($directives));
92
* Test if a cache is available for the given id and (if yes) return it (false else)
94
* For this test backend only, if $id == 'false', then the method will return false
95
* if $id == 'serialized', the method will return a serialized array
98
* @param string $id Cache id
99
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
100
* @return string Cached datas (or false)
102
public function load($id, $doNotTestCacheValidity = false)
104
$this->_addLog('get', array($id, $doNotTestCacheValidity));
108
if ($id=='serialized') {
109
return serialize(array('foo'));
111
if ($id=='serialized2') {
112
return serialize(array('headers' => array(), 'data' => 'foo'));
114
if (($id=='71769f39054f75894288e397df04e445') or ($id=='615d222619fb20b527168340cebd0578')) {
115
return serialize(array('foo', 'bar'));
117
if (($id=='8a02d218a5165c467e7a5747cc6bd4b6') or ($id=='648aca1366211d17cbf48e65dc570bee')) {
118
return serialize(array('foo', 'bar'));
124
* Test if a cache is available or not (for the given id)
126
* For this test backend only, if $id == 'false', then the method will return false
129
* @param string $id Cache id
130
* @return mixed|false false (a cache is not available) or "last modified" timestamp (int) of the available cache record
132
public function test($id)
134
$this->_addLog('test', array($id));
138
if (($id=='d8523b3ee441006261eeffa5c3d3a0a7') or ($id=='3c439c922209e2cb0b54d6deffccd75a')) {
141
if (($id=='40f649b94977c0a6e76902e2a0b43587') or ($id=='e83249ea22178277d5befc2c5e2e9ace')) {
148
* Save some string datas into a cache record
150
* For this test backend only, if $id == 'false', then the method will return false
153
* @param string $data Datas to cache
154
* @param string $id Cache id
155
* @param array $tags Array of strings, the cache record will be tagged by each string entry
156
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
157
* @return boolean True if no problem
159
public function save($data, $id, $tags = array(), $specificLifetime = false)
161
$this->_addLog('save', array($data, $id, $tags));
169
* Remove a cache record
171
* For this test backend only, if $id == 'false', then the method will return false
174
* @param string $id Cache id
175
* @return boolean True if no problem
177
public function remove($id)
179
$this->_addLog('remove', array($id));
187
* Clean some cache records
189
* For this test backend only, if $mode == 'false', then the method will return false
192
* Available modes are :
193
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
194
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
195
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
196
* ($tags can be an array of strings or a single string)
197
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
198
* ($tags can be an array of strings or a single string)
200
* @param string $mode Clean mode
201
* @param array $tags Array of tags
202
* @return boolean True if no problem
204
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
206
$this->_addLog('clean', array($mode, $tags));
207
if ($mode=='false') {
216
* @return string The last log
218
public function getLastLog()
220
return $this->_log[$this->_index - 1];
226
* @return int Log index
228
public function getLogIndex()
230
return $this->_index;
234
* Get the complete log array
236
* @return array Complete log array
238
public function getAllLogs()
244
* Return true if the automatic cleaning is available for the backend
248
public function isAutomaticCleaningAvailable()
254
* Add an event to the log array
256
* @param string $methodName MethodName
257
* @param array $args Arguments
260
private function _addLog($methodName, $args)
262
$this->_log[$this->_index] = array(
263
'methodName' => $methodName,
266
$this->_index = $this->_index + 1;