1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Horde_Cache_Storage_Eaccelerator extends Horde_Cache_Storage_Base
16: {
17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: public function __construct(array $params = array())
29: {
30: if (!function_exists('eaccelerator_gc')) {
31: throw new Horde_Cache_Exception('eAccelerator must be compiled with support for shared memory to use as caching backend.');
32: }
33:
34: parent::__construct(array_merge(array(
35: 'prefix' => '',
36: ), $params));
37: }
38:
39: 40:
41: public function get($key, $lifetime = 0)
42: {
43: $key = $this->_params['prefix'] . $key;
44: $this->_setExpire($key, $lifetime);
45: return eaccelerator_get($key);
46: }
47:
48: 49:
50: public function set($key, $data, $lifetime = 0)
51: {
52: $key = $this->_params['prefix'] . $key;
53: if (eaccelerator_put($key . '_expire', time(), $lifetime)) {
54: eaccelerator_put($key, $data, $lifetime);
55: }
56: }
57:
58: 59:
60: public function exists($key, $lifetime = 0)
61: {
62: $key = $this->_params['prefix'] . $key;
63: $this->_setExpire($key, $lifetime);
64: return eaccelerator_get($key) !== false;
65: }
66:
67: 68:
69: public function expire($key)
70: {
71: $key = $this->_params['prefix'] . $key;
72: eaccelerator_rm($key . '_expire');
73: return eaccelerator_rm($key);
74: }
75:
76: 77:
78: public function clear()
79: {
80: eaccelerator_clear();
81: }
82:
83: 84: 85: 86: 87: 88: 89:
90: protected function _setExpire($key, $lifetime)
91: {
92: if ($lifetime == 0) {
93:
94: return;
95: }
96:
97: $key = $this->_params['prefix'] . $key;
98: $expire = eaccelerator_get($key . '_expire');
99:
100:
101: if ($expire + $lifetime < time()) {
102:
103: eaccelerator_rm($key);
104: eaccelerator_rm($key . '_expire');
105: }
106: }
107:
108: }
109: