{"_$variable"})) { return $this->{"_$variable"}; } } /** * Read value(s) from the cache * * Note: When using an array of keys in $key for multi-read, * note that this is not an atomic operation. * * @param string $key The key to uniquely identify the cached item. * @return closure Function returning cached value if successful, `false` otherwise. */ public function read($key) { $cache =& $this->_cache; return function($self, $params) use (&$cache) { extract($params); if (is_array($key)) { $results = array(); foreach ($key as $k) { if (isset($cache[$k])) { $results[$k] = $cache[$k]; } } return $results; } return isset($cache[$key]) ? $cache[$key] : null; }; } /** * Write value(s) to the cache. * * Note: When using an array of keys => values in $key for multi-write, * note that this is not an atomic operation. * * @param string $key The key to uniquely identify the cached item. * @param mixed $data The value to be cached. * @param string $expiry A strtotime() compatible cache time. * @return closure Function returning boolean `true` on successful write, `false` otherwise. */ public function write($key, $data, $expiry) { $cache =& $this->_cache; return function($self, $params) use (&$cache) { extract($params); if (is_array($key)) { foreach ($key as $k => &$v) { $cache[$k] = $v; } return true; } return (boolean) ($cache[$key] = $data); }; } /** * Delete value from the cache * * @param string $key The key to uniquely identify the cached item. * @return closure Function returning boolean `true` on successful delete, `false` otherwise. */ public function delete($key) { $cache =& $this->_cache; return function($self, $params) use (&$cache) { extract($params); if (isset($cache[$key])) { unset($cache[$key]); return true; } else { return false; } }; } /** * Performs a decrement operation on specified numeric cache item. * * @param string $key Key of numeric cache item to decrement. * @param integer $offset Offset to decrement - defaults to 1. * @return closure Function returning item's new value on successful decrement, * `false` otherwise. */ public function decrement($key, $offset = 1) { $cache =& $this->_cache; return function($self, $params) use (&$cache, $offset) { extract($params); return $cache[$key] -= 1; }; } /** * Performs an increment operation on specified numeric cache item. * * @param string $key Key of numeric cache item to increment. * @param integer $offset Offset to increment - defaults to 1. * @return closure Function returning item's new value on successful increment, * `false` otherwise. */ public function increment($key, $offset = 1) { $cache =& $this->_cache; return function($self, $params) use (&$cache, $offset) { extract($params); return $cache[$key] += 1; }; } /** * Clears user-space cache * * @return mixed True on successful clear, false otherwise. */ public function clear() { foreach ($this->_cache as $key => &$value) { unset($this->_cache[$key]); } return true; } /** * This adapter is always enabled, as it has no external dependencies. * * @return boolean True */ public static function enabled() { return true; } /** * Garbage collection (GC) is not enabled for this adapter * * @return boolean False */ public function clean() { return false; } } ?>