2012-06-06 19:58:36 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Bart Visscher <bartv@thisnet.nl>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Thomas Tanghus <thomas@tanghus.net>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2012-06-06 19:58:36 +00:00
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2013-09-17 15:46:33 +00:00
|
|
|
namespace OC\Cache;
|
|
|
|
|
|
|
|
class Broker {
|
2013-09-18 20:22:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Cache
|
|
|
|
*/
|
2012-06-06 19:58:36 +00:00
|
|
|
protected $fast_cache;
|
2013-09-18 20:22:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Cache
|
|
|
|
*/
|
2012-06-06 19:58:36 +00:00
|
|
|
protected $slow_cache;
|
|
|
|
|
|
|
|
public function __construct($fast_cache, $slow_cache) {
|
|
|
|
$this->fast_cache = $fast_cache;
|
|
|
|
$this->slow_cache = $slow_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get($key) {
|
|
|
|
if ($r = $this->fast_cache->get($key)) {
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
return $this->slow_cache->get($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function set($key, $value, $ttl=0) {
|
2012-06-25 15:59:06 +00:00
|
|
|
if (!$this->fast_cache->set($key, $value, $ttl)) {
|
2012-06-06 19:58:36 +00:00
|
|
|
if ($this->fast_cache->hasKey($key)) {
|
|
|
|
$this->fast_cache->remove($key);
|
|
|
|
}
|
2012-06-25 15:59:06 +00:00
|
|
|
return $this->slow_cache->set($key, $value, $ttl);
|
2012-06-06 19:58:36 +00:00
|
|
|
}
|
2012-06-25 15:59:06 +00:00
|
|
|
return true;
|
2012-06-06 19:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function hasKey($key) {
|
|
|
|
if ($this->fast_cache->hasKey($key)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return $this->slow_cache->hasKey($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function remove($key) {
|
|
|
|
if ($this->fast_cache->remove($key)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return $this->slow_cache->remove($key);
|
|
|
|
}
|
|
|
|
|
2012-09-07 13:22:01 +00:00
|
|
|
public function clear($prefix='') {
|
2012-07-22 00:31:43 +00:00
|
|
|
$this->fast_cache->clear($prefix);
|
|
|
|
$this->slow_cache->clear($prefix);
|
2012-06-06 19:58:36 +00:00
|
|
|
}
|
|
|
|
}
|