Add disable container

This commit is contained in:
Aaron Carlino 2018-05-26 21:53:03 +12:00 committed by Damian Mooyman
parent 05384df10b
commit 5583565480
3 changed files with 30 additions and 7 deletions

6
cache/Cache.php vendored
View File

@ -146,7 +146,7 @@ class SS_Cache {
* @param string $frontend (optional) The type of Zend_Cache frontend
* @param array $frontendOptions (optional) Any frontend options to use.
*
* @return CacheProxy
* @return CacheProxy|Zend_Cache_Core
*/
public static function factory($for, $frontend='Output', $frontendOptions=null) {
self::init();
@ -192,6 +192,10 @@ class SS_Cache {
$frontend, $backend[0], $frontendOptions, $backend[1]
);
if (isset($frontendOptions['disable-container']) && $frontendOptions['disable-container']) {
return $container;
}
return Injector::inst()->createWithArgs('CacheProxy', [$container]);
}
}

View File

@ -2,8 +2,7 @@
require_once 'Zend/Cache.php';
class CacheProxy extends Zend_Cache_Core
{
class CacheProxy extends Zend_Cache_Core {
/**
* @var Zend_Cache_Backend|Zend_Cache_Backend_ExtendedInterface
*/
@ -13,8 +12,7 @@ class CacheProxy extends Zend_Cache_Core
* CacheProxy constructor.
* @param Zend_Cache_Core $container
*/
public function __construct(Zend_Cache_Core $container)
{
public function __construct(Zend_Cache_Core $container) {
$this->container = $container;
parent::__construct();
@ -23,8 +21,7 @@ class CacheProxy extends Zend_Cache_Core
/**
* @param array $directives
*/
public function setDirectives($directives)
{
public function setDirectives($directives) {
$this->container->setDirectives($directives);
}

View File

@ -92,5 +92,27 @@ class CacheTest extends SapphireTest {
}
public function testDisableVersionedCacheSegmentation() {
$cacheInstance = SS_Cache::factory('versioned_disabled', 'Output', ['disable-container' => true]);
$cacheInstance->clean();
Versioned::set_reading_mode('Stage.Live');
$result = $cacheInstance->load('test');
$this->assertFalse($result);
$cacheInstance->save('uncle', 'test');
$this->assertEquals('uncle', $cacheInstance->load('test'));
Versioned::set_reading_mode('Stage.Stage');
$this->assertEquals('uncle', $cacheInstance->load('test'));
$cacheInstance->save('cheese', 'test');
$cacheInstance->save('bar', 'foo');
$this->assertEquals('cheese', $cacheInstance->load('test'));
$this->assertEquals('bar', $cacheInstance->load('foo'));
Versioned::set_reading_mode('Stage.Live');
$this->assertEquals('bar', $cacheInstance->load('foo'));
$this->assertEquals('cheese', $cacheInstance->load('test'));
$cacheInstance->clean();
}
}