diff --git a/cache/Cache.php b/cache/Cache.php index 654a7540e..477eb86f4 100644 --- a/cache/Cache.php +++ b/cache/Cache.php @@ -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]); } } diff --git a/cache/CacheProxy.php b/cache/CacheProxy.php index 3f2eafda2..dd84bbece 100644 --- a/cache/CacheProxy.php +++ b/cache/CacheProxy.php @@ -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); } diff --git a/tests/cache/CacheTest.php b/tests/cache/CacheTest.php index 5a5467d24..9b6f54e95 100644 --- a/tests/cache/CacheTest.php +++ b/tests/cache/CacheTest.php @@ -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(); + } + }