mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
FIX: Deliberately clear partial cache blocks on flush (fixes #1383)
Move property to top of class definition Move property to top of class definition
This commit is contained in:
parent
b58d42f722
commit
48eb0e67e6
@ -101,7 +101,7 @@ class i18n extends Object implements TemplateGlobalProvider, Flushable {
|
|||||||
* Triggered early in the request when someone requests a flush.
|
* Triggered early in the request when someone requests a flush.
|
||||||
*/
|
*/
|
||||||
public static function flush() {
|
public static function flush() {
|
||||||
self::get_cache()->clean(Zend_Cache::CLEANING_MODE_ALL);
|
self::get_cache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('Zend_Translate'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,6 +124,18 @@ class SSViewerCacheBlockTest extends SapphireTest {
|
|||||||
$this->assertEquals($this->_runtemplate('<% cached %>$Foo<% end_cached %>', array('Foo' => 2)), '1');
|
$this->assertEquals($this->_runtemplate('<% cached %>$Foo<% end_cached %>', array('Foo' => 2)), '1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that the cacheblocks invalidate when a flush occurs.
|
||||||
|
*/
|
||||||
|
public function testBlocksInvalidateOnFlush() {
|
||||||
|
Director::test('/');
|
||||||
|
$this->_reset(true);
|
||||||
|
$this->assertEquals($this->_runtemplate('<% cached %>$Foo<% end_cached %>', array('Foo' => 1)), '1');
|
||||||
|
|
||||||
|
Director::test('/?flush=1');
|
||||||
|
$this->assertEquals($this->_runtemplate('<% cached %>$Foo<% end_cached %>', array('Foo' => 2)), '2');
|
||||||
|
}
|
||||||
|
|
||||||
public function testVersionedCache() {
|
public function testVersionedCache() {
|
||||||
|
|
||||||
$origStage = Versioned::current_stage();
|
$origStage = Versioned::current_stage();
|
||||||
|
@ -571,6 +571,16 @@ class SSViewer implements Flushable {
|
|||||||
*/
|
*/
|
||||||
private static $source_file_comments = false;
|
private static $source_file_comments = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
private static $template_cache_flushed = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
private static $cacheblock_cache_flushed = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether HTML comments indicating the source .SS file used to render this page should be
|
* Set whether HTML comments indicating the source .SS file used to render this page should be
|
||||||
* included in the output. This is enabled by default
|
* included in the output. This is enabled by default
|
||||||
@ -643,6 +653,7 @@ class SSViewer implements Flushable {
|
|||||||
*/
|
*/
|
||||||
public static function flush() {
|
public static function flush() {
|
||||||
self::flush_template_cache();
|
self::flush_template_cache();
|
||||||
|
self::flush_cacheblock_cache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -908,23 +919,32 @@ class SSViewer implements Flushable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
static private $flushed = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all parsed template files in the cache folder.
|
* Clears all parsed template files in the cache folder.
|
||||||
*
|
*
|
||||||
* Can only be called once per request (there may be multiple SSViewer instances).
|
* Can only be called once per request (there may be multiple SSViewer instances).
|
||||||
*/
|
*/
|
||||||
public static function flush_template_cache() {
|
public static function flush_template_cache() {
|
||||||
if (!self::$flushed) {
|
if (!self::$template_cache_flushed) {
|
||||||
$dir = dir(TEMP_FOLDER);
|
$dir = dir(TEMP_FOLDER);
|
||||||
while (false !== ($file = $dir->read())) {
|
while (false !== ($file = $dir->read())) {
|
||||||
if (strstr($file, '.cache')) unlink(TEMP_FOLDER . '/' . $file);
|
if (strstr($file, '.cache')) unlink(TEMP_FOLDER . '/' . $file);
|
||||||
}
|
}
|
||||||
self::$flushed = true;
|
self::$template_cache_flushed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all partial cache blocks.
|
||||||
|
*
|
||||||
|
* Can only be called once per request (there may be multiple SSViewer instances).
|
||||||
|
*/
|
||||||
|
public static function flush_cacheblock_cache() {
|
||||||
|
if (!self::$cacheblock_cache_flushed) {
|
||||||
|
$cache = SS_Cache::factory('cacheblock');
|
||||||
|
$tags = $cache->getTags();
|
||||||
|
$cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $tags);
|
||||||
|
self::$cacheblock_cache_flushed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user