2018-05-25 03:22:48 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'Zend/Cache.php';
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
/**
|
|
|
|
* A decorator for a Zend_Cache_Backend cache service that mutates cache keys
|
|
|
|
* dynamically depending on versioned state
|
|
|
|
*/
|
2018-05-26 11:53:03 +02:00
|
|
|
class CacheProxy extends Zend_Cache_Core {
|
2018-05-25 03:22:48 +02:00
|
|
|
/**
|
|
|
|
* @var Zend_Cache_Backend|Zend_Cache_Backend_ExtendedInterface
|
|
|
|
*/
|
2018-05-30 06:07:31 +02:00
|
|
|
protected $cache;
|
2018-05-25 03:22:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CacheProxy constructor.
|
2018-05-30 06:07:31 +02:00
|
|
|
* @param Zend_Cache_Core $cache
|
2018-05-25 03:22:48 +02:00
|
|
|
*/
|
2018-05-30 06:07:31 +02:00
|
|
|
public function __construct(Zend_Cache_Core $cache) {
|
|
|
|
$this->cache = $cache;
|
2018-05-25 03:22:48 +02:00
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2018-05-26 11:53:03 +02:00
|
|
|
public function setDirectives($directives) {
|
2018-05-30 06:07:31 +02:00
|
|
|
$this->cache->setDirectives($directives);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function setConfig(Zend_Config $config) {
|
|
|
|
return $this->cache->setConfig($config);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function setBackend(Zend_Cache_Backend $backendObject) {
|
|
|
|
return $this->cache->setBackend($backendObject);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function getBackend() {
|
|
|
|
return $this->cache->getBackend();
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function setOption($name, $value) {
|
|
|
|
$this->cache->setOption($name, $value);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function getOption($name) {
|
|
|
|
return $this->cache->getOption($name);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function setLifetime($newLifetime) {
|
|
|
|
return $this->cache->setLifetime($newLifetime);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function getIds() {
|
|
|
|
return $this->cache->getIds();
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function getTags() {
|
|
|
|
return $this->cache->getTags();
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function getIdsMatchingTags($tags = array()) {
|
|
|
|
return $this->cache->getIdsMatchingTags($tags);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function getIdsNotMatchingTags($tags = array()) {
|
|
|
|
return $this->cache->getIdsNotMatchingTags($tags);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function getIdsMatchingAnyTags($tags = array()) {
|
|
|
|
return $this->cache->getIdsMatchingAnyTags($tags);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function getFillingPercentage() {
|
|
|
|
return $this->cache->getFillingPercentage();
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function getMetadatas($id) {
|
|
|
|
return $this->cache->getMetadatas($this->getKeyID($id));
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function touch($id, $extraLifetime) {
|
|
|
|
return $this->cache->touch($this->getKeyID($id), $extraLifetime);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false) {
|
|
|
|
return $this->cache->load($this->getKeyID($id), $doNotTestCacheValidity, $doNotUnserialize);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function test($id) {
|
|
|
|
return $this->cache->test($this->getKeyID($id));
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8) {
|
|
|
|
return $this->cache->save(
|
2018-05-25 03:22:48 +02:00
|
|
|
$data,
|
2018-05-30 06:07:31 +02:00
|
|
|
$this->getKeyID($id),
|
2018-05-25 03:22:48 +02:00
|
|
|
$tags,
|
|
|
|
$specificLifetime,
|
|
|
|
$priority
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function remove($id) {
|
|
|
|
return $this->cache->remove($this->getKeyID($id));
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 06:07:31 +02:00
|
|
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) {
|
|
|
|
return $this->cache->clean($mode, $tags);
|
2018-05-25 03:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a dynamic key based on versioned state
|
2018-05-30 06:07:31 +02:00
|
|
|
* @param string $key
|
2018-05-25 03:22:48 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
2018-05-30 06:07:31 +02:00
|
|
|
protected function getKeyID($key) {
|
2018-05-25 03:22:48 +02:00
|
|
|
$state = Versioned::get_reading_mode();
|
|
|
|
if ($state) {
|
|
|
|
return $key . '_' . md5($state);
|
|
|
|
}
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
}
|