mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Refactor per chillu, reverse linting
This commit is contained in:
parent
5583565480
commit
265ad70011
123
cache/CacheProxy.php
vendored
123
cache/CacheProxy.php
vendored
@ -2,141 +2,118 @@
|
|||||||
|
|
||||||
require_once 'Zend/Cache.php';
|
require_once 'Zend/Cache.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A decorator for a Zend_Cache_Backend cache service that mutates cache keys
|
||||||
|
* dynamically depending on versioned state
|
||||||
|
*/
|
||||||
class CacheProxy extends Zend_Cache_Core {
|
class CacheProxy extends Zend_Cache_Core {
|
||||||
/**
|
/**
|
||||||
* @var Zend_Cache_Backend|Zend_Cache_Backend_ExtendedInterface
|
* @var Zend_Cache_Backend|Zend_Cache_Backend_ExtendedInterface
|
||||||
*/
|
*/
|
||||||
protected $container;
|
protected $cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CacheProxy constructor.
|
* CacheProxy constructor.
|
||||||
* @param Zend_Cache_Core $container
|
* @param Zend_Cache_Core $cache
|
||||||
*/
|
*/
|
||||||
public function __construct(Zend_Cache_Core $container) {
|
public function __construct(Zend_Cache_Core $cache) {
|
||||||
$this->container = $container;
|
$this->cache = $cache;
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $directives
|
|
||||||
*/
|
|
||||||
public function setDirectives($directives) {
|
public function setDirectives($directives) {
|
||||||
$this->container->setDirectives($directives);
|
$this->cache->setDirectives($directives);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setConfig(Zend_Config $config)
|
public function setConfig(Zend_Config $config) {
|
||||||
{
|
return $this->cache->setConfig($config);
|
||||||
return $this->container->setConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBackend(Zend_Cache_Backend $backendObject)
|
public function setBackend(Zend_Cache_Backend $backendObject) {
|
||||||
{
|
return $this->cache->setBackend($backendObject);
|
||||||
return $this->container->setBackend($backendObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBackend()
|
public function getBackend() {
|
||||||
{
|
return $this->cache->getBackend();
|
||||||
return $this->container->getBackend();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setOption($name, $value) {
|
||||||
* @param string $name
|
$this->cache->setOption($name, $value);
|
||||||
* @param mixed $value
|
|
||||||
*/
|
|
||||||
public function setOption($name, $value)
|
|
||||||
{
|
|
||||||
$this->container->setOption($name, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOption($name)
|
public function getOption($name) {
|
||||||
{
|
return $this->cache->getOption($name);
|
||||||
return $this->container->getOption($name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setLifetime($newLifetime)
|
public function setLifetime($newLifetime) {
|
||||||
{
|
return $this->cache->setLifetime($newLifetime);
|
||||||
return $this->container->setLifetime($newLifetime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIds()
|
public function getIds() {
|
||||||
{
|
return $this->cache->getIds();
|
||||||
return $this->container->getIds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTags()
|
public function getTags() {
|
||||||
{
|
return $this->cache->getTags();
|
||||||
return $this->container->getTags();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIdsMatchingTags($tags = array())
|
public function getIdsMatchingTags($tags = array()) {
|
||||||
{
|
return $this->cache->getIdsMatchingTags($tags);
|
||||||
return $this->container->getIdsMatchingTags($tags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIdsNotMatchingTags($tags = array())
|
public function getIdsNotMatchingTags($tags = array()) {
|
||||||
{
|
return $this->cache->getIdsNotMatchingTags($tags);
|
||||||
return $this->container->getIdsNotMatchingTags($tags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIdsMatchingAnyTags($tags = array())
|
public function getIdsMatchingAnyTags($tags = array()) {
|
||||||
{
|
return $this->cache->getIdsMatchingAnyTags($tags);
|
||||||
return $this->container->getIdsMatchingAnyTags($tags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFillingPercentage()
|
public function getFillingPercentage() {
|
||||||
{
|
return $this->cache->getFillingPercentage();
|
||||||
return $this->container->getFillingPercentage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMetadatas($id)
|
public function getMetadatas($id) {
|
||||||
{
|
return $this->cache->getMetadatas($this->getKeyID($id));
|
||||||
return $this->container->getMetadatas($this->createKey($id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function touch($id, $extraLifetime)
|
public function touch($id, $extraLifetime) {
|
||||||
{
|
return $this->cache->touch($this->getKeyID($id), $extraLifetime);
|
||||||
return $this->container->touch($this->createKey($id), $extraLifetime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false)
|
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false) {
|
||||||
{
|
return $this->cache->load($this->getKeyID($id), $doNotTestCacheValidity, $doNotUnserialize);
|
||||||
return $this->container->load($this->createKey($id), $doNotTestCacheValidity, $doNotUnserialize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test($id)
|
public function test($id) {
|
||||||
{
|
return $this->cache->test($this->getKeyID($id));
|
||||||
return $this->container->test($this->createKey($id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8)
|
public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8) {
|
||||||
{
|
return $this->cache->save(
|
||||||
return $this->container->save(
|
|
||||||
$data,
|
$data,
|
||||||
$this->createKey($id),
|
$this->getKeyID($id),
|
||||||
$tags,
|
$tags,
|
||||||
$specificLifetime,
|
$specificLifetime,
|
||||||
$priority
|
$priority
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove($id)
|
public function remove($id) {
|
||||||
{
|
return $this->cache->remove($this->getKeyID($id));
|
||||||
return $this->container->remove($this->createKey($id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) {
|
||||||
{
|
return $this->cache->clean($mode, $tags);
|
||||||
return $this->container->clean($mode, $tags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a dynamic key based on versioned state
|
* Creates a dynamic key based on versioned state
|
||||||
* @param $key
|
* @param string $key
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function createKey($key)
|
protected function getKeyID($key) {
|
||||||
{
|
|
||||||
$state = Versioned::get_reading_mode();
|
$state = Versioned::get_reading_mode();
|
||||||
if ($state) {
|
if ($state) {
|
||||||
return $key . '_' . md5($state);
|
return $key . '_' . md5($state);
|
||||||
|
40
tests/cache/CacheTest.php
vendored
40
tests/cache/CacheTest.php
vendored
@ -74,19 +74,19 @@ class CacheTest extends SapphireTest {
|
|||||||
$cacheInstance->clean();
|
$cacheInstance->clean();
|
||||||
|
|
||||||
Versioned::set_reading_mode('Stage.Live');
|
Versioned::set_reading_mode('Stage.Live');
|
||||||
$result = $cacheInstance->load('test');
|
$result = $cacheInstance->load('shared_key');
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
$cacheInstance->save('uncle', 'test');
|
$cacheInstance->save('uncle', 'shared_key');
|
||||||
$this->assertEquals('uncle', $cacheInstance->load('test'));
|
$this->assertEquals('uncle', $cacheInstance->load('shared_key'), 'Shared key is cached on LIVE');
|
||||||
Versioned::set_reading_mode('Stage.Stage');
|
Versioned::set_reading_mode('Stage.Stage');
|
||||||
$this->assertFalse($cacheInstance->load('test'));
|
$this->assertFalse($cacheInstance->load('shared_key'), 'Shared key does not exist on STAGE');
|
||||||
$cacheInstance->save('cheese', 'test');
|
$cacheInstance->save('cheese', 'shared_key');
|
||||||
$cacheInstance->save('bar', 'foo');
|
$cacheInstance->save('bar', 'stage_key');
|
||||||
$this->assertEquals('cheese', $cacheInstance->load('test'));
|
$this->assertEquals('cheese', $cacheInstance->load('shared_key'), 'Shared key has its own value on STAGE');
|
||||||
$this->assertEquals('bar', $cacheInstance->load('foo'));
|
$this->assertEquals('bar', $cacheInstance->load('stage_key'), 'New key is cached on STAGE');
|
||||||
Versioned::set_reading_mode('Stage.Live');
|
Versioned::set_reading_mode('Stage.Live');
|
||||||
$this->assertFalse($cacheInstance->load('foo'));
|
$this->assertFalse($cacheInstance->load('stage_key'), 'New key does not exist on LIVE');
|
||||||
$this->assertEquals('uncle', $cacheInstance->load('test'));
|
$this->assertEquals('uncle', $cacheInstance->load('shared_key'), 'Shared key retains its own value on LIVE');
|
||||||
|
|
||||||
$cacheInstance->clean();
|
$cacheInstance->clean();
|
||||||
|
|
||||||
@ -97,19 +97,19 @@ class CacheTest extends SapphireTest {
|
|||||||
$cacheInstance->clean();
|
$cacheInstance->clean();
|
||||||
|
|
||||||
Versioned::set_reading_mode('Stage.Live');
|
Versioned::set_reading_mode('Stage.Live');
|
||||||
$result = $cacheInstance->load('test');
|
$result = $cacheInstance->load('shared_key');
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
$cacheInstance->save('uncle', 'test');
|
$cacheInstance->save('uncle', 'shared_key');
|
||||||
$this->assertEquals('uncle', $cacheInstance->load('test'));
|
$this->assertEquals('uncle', $cacheInstance->load('shared_key'), 'Shared key is cached on LIVE');
|
||||||
Versioned::set_reading_mode('Stage.Stage');
|
Versioned::set_reading_mode('Stage.Stage');
|
||||||
$this->assertEquals('uncle', $cacheInstance->load('test'));
|
$this->assertEquals('uncle', $cacheInstance->load('shared_key'), 'Shared key is same on STAGE');
|
||||||
$cacheInstance->save('cheese', 'test');
|
$cacheInstance->save('cheese', 'shared_key');
|
||||||
$cacheInstance->save('bar', 'foo');
|
$cacheInstance->save('bar', 'stage_key');
|
||||||
$this->assertEquals('cheese', $cacheInstance->load('test'));
|
$this->assertEquals('cheese', $cacheInstance->load('shared_key'), 'Shared key is overwritten on STAGE');
|
||||||
$this->assertEquals('bar', $cacheInstance->load('foo'));
|
$this->assertEquals('bar', $cacheInstance->load('stage_key'), 'New key is written on STAGE');
|
||||||
Versioned::set_reading_mode('Stage.Live');
|
Versioned::set_reading_mode('Stage.Live');
|
||||||
$this->assertEquals('bar', $cacheInstance->load('foo'));
|
$this->assertEquals('bar', $cacheInstance->load('stage_key'), 'New key has same value on LIVE');
|
||||||
$this->assertEquals('cheese', $cacheInstance->load('test'));
|
$this->assertEquals('cheese', $cacheInstance->load('shared_key'), 'New value for existing key is same on LIVE');
|
||||||
|
|
||||||
$cacheInstance->clean();
|
$cacheInstance->clean();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user