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 eAccelerator (version 0.9.5+).
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_Eaccelerator extends Horde_Cache_Storage_Base
28
* @param array $params Optional parameters:
29
* - prefix: (string) The prefix to use for the cache keys.
32
* @throws Horde_Cache_Exception
34
public function __construct(array $params = array())
36
if (!function_exists('eaccelerator_gc')) {
37
throw new Horde_Cache_Exception('eAccelerator must be compiled with support for shared memory to use as caching backend.');
40
parent::__construct(array_merge(array(
47
public function get($key, $lifetime = 0)
49
$key = $this->_params['prefix'] . $key;
50
$this->_setExpire($key, $lifetime);
51
return eaccelerator_get($key);
56
public function set($key, $data, $lifetime = 0)
58
$key = $this->_params['prefix'] . $key;
59
if (eaccelerator_put($key . '_expire', time(), $lifetime)) {
60
eaccelerator_put($key, $data, $lifetime);
66
public function exists($key, $lifetime = 0)
68
$key = $this->_params['prefix'] . $key;
69
$this->_setExpire($key, $lifetime);
70
return eaccelerator_get($key) !== false;
75
public function expire($key)
77
$key = $this->_params['prefix'] . $key;
78
eaccelerator_rm($key . '_expire');
79
return eaccelerator_rm($key);
84
public function clear()
90
* Set expire time on each call since eAccelerator sets it on
93
* @param string $key Cache key to expire.
94
* @param integer $lifetime Lifetime of the data in seconds.
96
protected function _setExpire($key, $lifetime)
103
$key = $this->_params['prefix'] . $key;
104
$expire = eaccelerator_get($key . '_expire');
107
if ($expire + $lifetime < time()) {
109
eaccelerator_rm($key);
110
eaccelerator_rm($key . '_expire');