From 535790565bcea823bbb527c13c33f49f7ef1b4ce Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Tue, 27 Apr 2010 07:22:04 +0200 Subject: [PATCH] Add a mock cache driver. --- framework/Cache/lib/Horde/Cache/Mock.php | 91 ++++++++++++++++++++++++++++++++ framework/Cache/package.xml | 2 + 2 files changed, 93 insertions(+) create mode 100644 framework/Cache/lib/Horde/Cache/Mock.php diff --git a/framework/Cache/lib/Horde/Cache/Mock.php b/framework/Cache/lib/Horde/Cache/Mock.php new file mode 100644 index 000000000..55ee5e95b --- /dev/null +++ b/framework/Cache/lib/Horde/Cache/Mock.php @@ -0,0 +1,91 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Cache + */ +class Horde_Cache_Mock extends Horde_Cache_Base +{ + /** + * The storage location for this cache. + * + * @var array + */ + private $_cache = array(); + + /** + * Construct a new Horde_Cache_Mock object. + * + * @param array $params Configuration parameters: + */ + public function __construct($params = array()) + { + parent::__construct($params); + } + + /** + * Attempts to retrieve a piece of cached data and return it to the caller. + * + * @param string $key Cache key to fetch. + * @param integer $lifetime Lifetime of the key in seconds. + * + * @return mixed Cached data, or false if none was found. + */ + public function get($key, $lifetime = 1) + { + return isset($this->_cache[$key]) + ? $this->_cache[$key] + : false; + } + + /** + * Attempts to store an object to the cache. + * + * @param string $key Cache key (identifier). + * @param mixed $data Data to store in the cache. + * @param integer $lifetime Data lifetime. + * + * @return boolean True on success, false on failure. + */ + public function set($key, $data, $lifetime = null) + { + $this->_cache[$key] = $data; + } + + /** + * Checks if a given key exists in the cache, valid for the given + * lifetime. + * + * @param string $key Cache key to check. + * @param integer $lifetime Lifetime of the key in seconds. + * + * @return boolean Existence. + */ + public function exists($key, $lifetime = 1) + { + return isset($this->_cache[$key]); + } + + /** + * Expire any existing data for the given key. + * + * @param string $key Cache key to expire. + * + * @return boolean Success or failure. + */ + public function expire($key) + { + unset($this->_cache[$key]); + } +} diff --git a/framework/Cache/package.xml b/framework/Cache/package.xml index 4e2a03f80..04ae2fd7a 100644 --- a/framework/Cache/package.xml +++ b/framework/Cache/package.xml @@ -48,6 +48,7 @@ Performance Suite's content cache), memcached, or an SQL table. + @@ -94,6 +95,7 @@ Performance Suite's content cache), memcached, or an SQL table. + -- 2.11.0