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 in eAccelerator (version 0.9.5+).
17
* @author Duck <duck@obala.net>
19
* @copyright 2006-2014 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:
30
* - prefix: (string) The prefix to use for the cache keys.
34
* @throws Horde_Cache_Exception
36
public function __construct(array $params = array())
38
if (!function_exists('eaccelerator_gc')) {
39
throw new Horde_Cache_Exception('eAccelerator must be compiled with support for shared memory to use as caching backend.');
42
parent::__construct(array_merge(array(
49
public function get($key, $lifetime = 0)
51
$key = $this->_params['prefix'] . $key;
52
$this->_setExpire($key, $lifetime);
53
return eaccelerator_get($key);
58
public function set($key, $data, $lifetime = 0)
60
$key = $this->_params['prefix'] . $key;
61
if (eaccelerator_put($key . '_expire', time(), $lifetime)) {
62
eaccelerator_put($key, $data, $lifetime);
68
public function exists($key, $lifetime = 0)
70
$key = $this->_params['prefix'] . $key;
71
$this->_setExpire($key, $lifetime);
72
return eaccelerator_get($key) !== false;
77
public function expire($key)
79
$key = $this->_params['prefix'] . $key;
80
eaccelerator_rm($key . '_expire');
81
return eaccelerator_rm($key);
86
public function clear()
92
* Set expire time on each call since eAccelerator sets it on
95
* @param string $key Cache key to expire.
96
* @param integer $lifetime Lifetime of the data in seconds.
98
protected function _setExpire($key, $lifetime)
100
if ($lifetime == 0) {
105
$expire = eaccelerator_get($key . '_expire');
108
if ($expire + $lifetime < time()) {
110
eaccelerator_rm($key);
111
eaccelerator_rm($key . '_expire');