3
* Copyright 2006-2013 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-2013 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-2013 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:
46
* - memcache: (Horde_Memcache) [REQUIRED] A Horde_Memcache object.
47
* - prefix: (string) The prefix to use for the cache keys.
50
public function __construct(array $params = array())
52
if (!isset($params['memcache'])) {
53
if (isset($params['hashtable'])) {
54
$params['memcache'] = $params['hashtable'];
56
throw new InvalidArgumentException('Missing memcache object');
60
parent::__construct(array_merge(array(
67
protected function _initOb()
69
$this->_memcache = $this->_params['memcache'];
74
public function get($key, $lifetime = 0)
77
$key = $this->_params['prefix'] . $key;
78
if (isset($this->_expirecache[$key])) {
79
return $this->_expirecache[$key];
82
$key_list = array($key);
83
if (!empty($lifetime)) {
84
$key_list[] = $key . '_e';
87
$res = $this->_memcache->get($key_list);
90
unset($this->_expirecache[$key]);
92
// If we can't find the expire time, assume we have exceeded it.
93
if (empty($lifetime) ||
94
(($res[$key . '_e'] !== false) && ($res[$key . '_e'] + $lifetime > time()))) {
95
$this->_expirecache[$key] = $res[$key];
98
$this->expire($original_key);
107
public function set($key, $data, $lifetime = 0)
109
$key = $this->_params['prefix'] . $key;
111
if ($this->_memcache->set($key . '_e', time(), $lifetime) !== false) {
112
$this->_memcache->set($key, $data, $lifetime);
118
public function exists($key, $lifetime = 0)
120
return ($this->get($key, $lifetime) !== false);
125
public function expire($key)
127
$key = $this->_params['prefix'] . $key;
128
unset($this->_expirecache[$key]);
129
$this->_memcache->delete($key . '_e');
131
return $this->_memcache->delete($key);
136
public function clear()
138
$this->_memcache->flush();