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