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 the Alternative PHP Cache (APC).
17
* Copyright 2006-2014 Horde LLC (http://www.horde.org/)
19
* See the enclosed file COPYING for license information (LGPL). If you
20
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
22
* @author Duck <duck@obala.net>
24
* @copyright 2006-2014 Horde LLC
25
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
28
class Horde_Cache_Storage_Apc extends Horde_Cache_Storage_Base
33
* @param array $params Optional parameters:
35
* - prefix: (string) The prefix to use for the cache keys.
39
public function __construct(array $params = array())
41
parent::__construct(array_merge(array(
48
public function get($key, $lifetime = 0)
50
$key = $this->_params['prefix'] . $key;
51
$this->_setExpire($key, $lifetime);
52
return apc_fetch($key);
57
public function set($key, $data, $lifetime = 0)
59
$key = $this->_params['prefix'] . $key;
60
if (apc_store($key . '_expire', time(), $lifetime)) {
61
apc_store($key, $data, $lifetime);
67
public function exists($key, $lifetime = 0)
69
$key = $this->_params['prefix'] . $key;
70
$this->_setExpire($key, $lifetime);
71
return (apc_fetch($key) !== false);
76
public function expire($key)
78
$key = $this->_params['prefix'] . $key;
79
apc_delete($key . '_expire');
80
return apc_delete($key);
85
public function clear()
87
if (!apc_clear_cache('user')) {
88
throw new Horde_Cache_Exception('Clearing APC cache failed');
93
* Set expire time on each call since APC sets it on cache creation.
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 = apc_fetch($key . '_expire');
108
if ($expire + $lifetime < time()) {
111
apc_delete($key . '_expire');