mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-06 01:31:22 +02:00
Add disable container
This commit is contained in:
parent
05384df10b
commit
5583565480
6
cache/Cache.php
vendored
6
cache/Cache.php
vendored
@ -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]);
|
||||
}
|
||||
}
|
||||
|
9
cache/CacheProxy.php
vendored
9
cache/CacheProxy.php
vendored
@ -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);
|
||||
}
|
||||
|
||||
|
22
tests/cache/CacheTest.php
vendored
22
tests/cache/CacheTest.php
vendored
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user