2012-06-06 23:58:36 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-02-26 13:37:37 +03:00
|
|
|
* Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
2012-06-06 23:58:36 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2013-09-17 19:46:33 +04:00
|
|
|
namespace OC\Cache;
|
|
|
|
|
|
|
|
class Broker {
|
2013-09-19 00:22:51 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Cache
|
|
|
|
*/
|
2012-06-06 23:58:36 +04:00
|
|
|
protected $fast_cache;
|
2013-09-19 00:22:51 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Cache
|
|
|
|
*/
|
2012-06-06 23:58:36 +04: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 19:59:06 +04:00
|
|
|
if (!$this->fast_cache->set($key, $value, $ttl)) {
|
2012-06-06 23:58:36 +04:00
|
|
|
if ($this->fast_cache->hasKey($key)) {
|
|
|
|
$this->fast_cache->remove($key);
|
|
|
|
}
|
2012-06-25 19:59:06 +04:00
|
|
|
return $this->slow_cache->set($key, $value, $ttl);
|
2012-06-06 23:58:36 +04:00
|
|
|
}
|
2012-06-25 19:59:06 +04:00
|
|
|
return true;
|
2012-06-06 23:58:36 +04: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 17:22:01 +04:00
|
|
|
public function clear($prefix='') {
|
2012-07-22 04:31:43 +04:00
|
|
|
$this->fast_cache->clear($prefix);
|
|
|
|
$this->slow_cache->clear($prefix);
|
2012-06-06 23:58:36 +04:00
|
|
|
}
|
|
|
|
}
|