3
* Copyright 2006-2014 Horde LLC (http://www.horde.org/)
5
* See the enclosed file COPYING for license information (LGPL). If you
6
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
9
* @copyright 2006-2014 Horde LLC
10
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
15
* Cache storage on a memcache installation.
17
* @author Duck <duck@obala.net>
18
* @author Michael Slusarz <slusarz@horde.org>
20
* @copyright 2006-2014 Horde LLC
21
* @deprecated Use HashTable driver instead.
22
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
25
class Horde_Cache_Storage_Memcache extends Horde_Cache_Storage_Base
28
* Cache results of expire() calls (since we will get the entire object
29
* on an expire() call anyway).
33
protected $_expirecache = array();
43
* Construct a new Horde_Cache_Memcache object.
45
* @param array $params Parameter array:
47
* - memcache: (Horde_Memcache) [REQUIRED] A Horde_Memcache object.
48
* - prefix: (string) The prefix to use for the cache keys.
52
public function __construct(array $params = array())
54
if (!isset($params['memcache'])) {
55
if (isset($params['hashtable'])) {
56
$params['memcache'] = $params['hashtable'];
58
throw new InvalidArgumentException('Missing memcache object');
62
parent::__construct(array_merge(array(
69
protected function _initOb()
71
$this->_memcache = $this->_params['memcache'];
76
public function get($key, $lifetime = 0)
79
$key = $this->_params['prefix'] . $key;
80
if (isset($this->_expirecache[$key])) {
81
return $this->_expirecache[$key];
84
$key_list = array($key);
85
if (!empty($lifetime)) {
86
$key_list[] = $key . '_e';
89
$res = $this->_memcache->get($key_list);
92
unset($this->_expirecache[$key]);
94
// If we can't find the expire time, assume we have exceeded it.
95
if (empty($lifetime) ||
96
(($res[$key . '_e'] !== false) && ($res[$key . '_e'] + $lifetime > time()))) {
97
$this->_expirecache[$key] = $res[$key];
100
$this->expire($original_key);
109
public function set($key, $data, $lifetime = 0)
111
$key = $this->_params['prefix'] . $key;
113
if ($this->_memcache->set($key . '_e', time(), $lifetime) !== false) {
114
$this->_memcache->set($key, $data, $lifetime);
120
public function exists($key, $lifetime = 0)
122
return ($this->get($key, $lifetime) !== false);
127
public function expire($key)
129
$key = $this->_params['prefix'] . $key;
130
unset($this->_expirecache[$key]);
131
$this->_memcache->delete($key . '_e');
133
return $this->_memcache->delete($key);
138
public function clear()
140
$this->_memcache->flush();