FIX: Tag-less cache backends error on flush

This commit is contained in:
Loz Calver 2014-10-15 11:25:02 +01:00
parent 73c52a6eeb
commit 570f261302
3 changed files with 40 additions and 11 deletions

View File

@ -101,7 +101,18 @@ 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_MATCHING_TAG, array('Zend_Translate')); $cache = self::get_cache();
$backend = $cache->getBackend();
if(
$backend instanceof Zend_Cache_Backend_ExtendedInterface
&& ($capabilities = $backend->getCapabilities())
&& $capabilities['tags']
) {
$cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $cache->getTags());
} else {
$cache->clean(Zend_Cache::CLEANING_MODE_ALL);
}
} }
/** /**

View File

@ -50,15 +50,22 @@ class Aggregate extends ViewableData {
*/ */
public static function flushCache($class=null) { public static function flushCache($class=null) {
$cache = self::cache(); $cache = self::cache();
$capabilities = $cache->getBackend()->getCapabilities(); $backend = $cache->getBackend();
if($capabilities['tags'] && (!$class || $class == 'DataObject')) {
if(
$backend instanceof Zend_Cache_Backend_ExtendedInterface
&& ($capabilities = $backend->getCapabilities())
&& $capabilities['tags']
) {
if( ! $class || $class == 'DataObject') {
$cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('aggregate')); $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('aggregate'));
} elseif($capabilities['tags']) { } else {
$tags = ClassInfo::ancestry($class); $tags = ClassInfo::ancestry($class);
foreach($tags as &$tag) { foreach($tags as &$tag) {
$tag = preg_replace('/[^a-zA-Z0-9_]/', '_', $tag); $tag = preg_replace('/[^a-zA-Z0-9_]/', '_', $tag);
} }
$cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $tags); $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $tags);
}
} else { } else {
$cache->clean(Zend_Cache::CLEANING_MODE_ALL); $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
} }

View File

@ -948,8 +948,19 @@ class SSViewer implements Flushable {
public static function flush_cacheblock_cache($force = false) { public static function flush_cacheblock_cache($force = false) {
if (!self::$cacheblock_cache_flushed || $force) { if (!self::$cacheblock_cache_flushed || $force) {
$cache = SS_Cache::factory('cacheblock'); $cache = SS_Cache::factory('cacheblock');
$tags = $cache->getTags(); $backend = $cache->getBackend();
$cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $tags);
if(
$backend instanceof Zend_Cache_Backend_ExtendedInterface
&& ($capabilities = $backend->getCapabilities())
&& $capabilities['tags']
) {
$cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $cache->getTags());
} else {
$cache->clean(Zend_Cache::CLEANING_MODE_ALL);
}
self::$cacheblock_cache_flushed = true; self::$cacheblock_cache_flushed = true;
} }
} }