1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Horde_Cache_Storage_Apc 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: return apc_fetch($key);
40: }
41:
42: 43:
44: public function set($key, $data, $lifetime = 0)
45: {
46: $key = $this->_params['prefix'] . $key;
47: if (apc_store($key . '_expire', time(), $lifetime)) {
48: apc_store($key, $data, $lifetime);
49: }
50: }
51:
52: 53:
54: public function exists($key, $lifetime = 0)
55: {
56: $key = $this->_params['prefix'] . $key;
57: $this->_setExpire($key, $lifetime);
58: return (apc_fetch($key) !== false);
59: }
60:
61: 62:
63: public function expire($key)
64: {
65: $key = $this->_params['prefix'] . $key;
66: apc_delete($key . '_expire');
67: return apc_delete($key);
68: }
69:
70: 71:
72: public function clear()
73: {
74: if (!apc_clear_cache('user')) {
75: throw new Horde_Cache_Exception('Clearing APC cache failed');
76: }
77: }
78:
79: 80: 81: 82: 83: 84:
85: protected function _setExpire($key, $lifetime)
86: {
87: $key = $this->_params['prefix'] . $key;
88: if ($lifetime == 0) {
89:
90: return;
91: }
92:
93: $expire = apc_fetch($key . '_expire');
94:
95:
96: if ($expire + $lifetime < time()) {
97:
98: apc_delete($key);
99: apc_delete($key . '_expire');
100: }
101: }
102:
103: }
104: