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 in Xcache.
17
* @author Duck <duck@obala.net>
19
* @copyright 2006-2013 Horde LLC
20
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
23
class Horde_Cache_Storage_Xcache extends Horde_Cache_Storage_Base
28
* @param array $params Optional parameters:
29
* - prefix: (string) The prefix to use for the cache keys.
32
public function __construct(array $params = array())
34
parent::__construct(array_merge(array(
41
public function get($key, $lifetime = 0)
43
$key = $this->_params['prefix'] . $key;
44
$this->_setExpire($key, $lifetime);
45
$result = xcache_get($key);
54
public function set($key, $data, $lifetime = 0)
56
$key = $this->_params['prefix'] . $key;
57
if (xcache_set($key . '_expire', time(), $lifetime)) {
58
xcache_set($key, $data, $lifetime);
64
public function exists($key, $lifetime = 0)
66
$key = $this->_params['prefix'] . $key;
67
$this->_setExpire($key, $lifetime);
68
return xcache_isset($key);
73
public function expire($key)
75
$key = $this->_params['prefix'] . $key;
76
xcache_unset($key . '_expire');
77
return xcache_unset($key);
82
public function clear()
84
// xcache_clear_cache() won't work because it requires HTTP Auth.
85
throw new Horde_Cache_Exception('Not supported');
89
* Set expire time on each call since memcache sets it on cache creation.
91
* @param string $key Cache key to expire.
92
* @param integer $lifetime Lifetime of the data in seconds.
94
protected function _setExpire($key, $lifetime)
100
$key = $this->_params['prefix'] . $key;
101
$expire = xcache_get($key . '_expire');
104
if ($expire + $lifetime < time()) {
106
xcache_unset($key . '_expire');