mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02: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.
|
||||
*/
|
||||
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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,6 +123,18 @@ class SSViewerCacheBlockTest extends SapphireTest {
|
||||
$this->assertEquals($this->_runtemplate('<% cached %>$Foo<% end_cached %>', array('Foo' => 1)), '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() {
|
||||
|
||||
|
@ -571,6 +571,16 @@ class SSViewer implements Flushable {
|
||||
*/
|
||||
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
|
||||
* included in the output. This is enabled by default
|
||||
@ -643,6 +653,7 @@ class SSViewer implements Flushable {
|
||||
*/
|
||||
public static function flush() {
|
||||
self::flush_template_cache();
|
||||
self::flush_cacheblock_cache();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -907,11 +918,6 @@ class SSViewer implements Flushable {
|
||||
return $founds[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
static private $flushed = false;
|
||||
|
||||
/**
|
||||
* Clears all parsed template files in the cache folder.
|
||||
@ -919,12 +925,26 @@ class SSViewer implements Flushable {
|
||||
* Can only be called once per request (there may be multiple SSViewer instances).
|
||||
*/
|
||||
public static function flush_template_cache() {
|
||||
if (!self::$flushed) {
|
||||
if (!self::$template_cache_flushed) {
|
||||
$dir = dir(TEMP_FOLDER);
|
||||
while (false !== ($file = $dir->read())) {
|
||||
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…
Reference in New Issue
Block a user