3
* Copyright 2010-2013 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 2010-2013 Horde LLC
10
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
15
* Driver that loops through a given list of storage drivers to search for a
16
* cached value. Allows for use of caching backends on top of persistent
19
* @author Michael Slusarz <slusarz@horde.org>
21
* @copyright 2010-2013 Horde LLC
22
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
25
class Horde_Cache_Storage_Stack extends Horde_Cache_Storage_Base
28
* Stack of cache drivers.
32
protected $_stack = array();
37
* @param array $params Parameters:
38
* - stack: (array) [REQUIRED] An array of storage instances to loop
39
* through, in order of priority. The last entry is considered
40
* the 'master' driver, for purposes of writes.
42
public function __construct(array $params = array())
44
if (!isset($params['stack'])) {
45
throw new InvalidArgumentException('Missing stack parameter.');
48
parent::__construct($params);
53
protected function _initOb()
55
$this->_stack = $this->_params['stack'];
60
public function get($key, $lifetime = 0)
62
foreach ($this->_stack as $val) {
63
$result = $val->get($key, $lifetime);
64
if ($result !== false) {
74
public function set($key, $data, $lifetime = 0)
76
/* Do writes in *reverse* order - it is OK if a write to one of the
77
* non-master backends fails. */
80
foreach (array_reverse($this->_stack) as $val) {
81
$result = $val->set($key, $data, $lifetime);
82
if ($result === false) {
87
/* Attempt to invalidate cache if write failed. */
96
public function exists($key, $lifetime = 0)
98
foreach ($this->_stack as $val) {
99
$result = $val->exists($key, $lifetime);
100
if ($result === true) {
110
public function expire($key)
112
/* Only report success from master. */
113
$master = $success = true;
115
foreach (array_reverse($this->_stack) as $val) {
116
$result = $val->expire($key);
117
if ($master && ($result === false)) {
128
public function clear()
130
/* Only report errors from master. */
134
foreach (array_reverse($this->_stack) as $val) {
137
} catch (Horde_Cache_Exception $e) {