mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR: stop Aggregate clear cache on DataObject::write()
see: https://github.com/silverstripe/silverstripe-framework/issues/6383 for details
This commit is contained in:
parent
c8525c026c
commit
f027b5eaf5
@ -41,9 +41,25 @@ class Aggregate extends ViewableData {
|
|||||||
|
|
||||||
/** Build & cache the cache object */
|
/** Build & cache the cache object */
|
||||||
protected static function cache() {
|
protected static function cache() {
|
||||||
|
self::set_as_file_cache_to_avoid_clearing_entire_cache();
|
||||||
return self::$cache ? self::$cache : (self::$cache = SS_Cache::factory('aggregate'));
|
return self::$cache ? self::$cache : (self::$cache = SS_Cache::factory('aggregate'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* make sure aggregate always uses File caching
|
||||||
|
* as many of the other caches will clear all caches
|
||||||
|
* everytime the DataObject is written...
|
||||||
|
* @see: https://github.com/silverstripe/silverstripe-framework/issues/6383
|
||||||
|
*/
|
||||||
|
protected static function set_as_file_cache_to_avoid_clearing_entire_cache()
|
||||||
|
{
|
||||||
|
$cachedir = TEMP_FOLDER . DIRECTORY_SEPARATOR . 'aggregatecache';
|
||||||
|
if (!is_dir($cachedir)) {
|
||||||
|
mkdir($cachedir);
|
||||||
|
}
|
||||||
|
SS_Cache::add_backend('aggregatecache', 'File', array('cache_dir' => $cachedir));
|
||||||
|
SS_Cache::pick_backend('aggregatecache', 'aggregate');
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Clear the aggregate cache for a given type, or pass nothing to clear all aggregate caches.
|
* Clear the aggregate cache for a given type, or pass nothing to clear all aggregate caches.
|
||||||
* {@link $class} is just effective if the cache backend supports tags.
|
* {@link $class} is just effective if the cache backend supports tags.
|
||||||
@ -76,6 +92,7 @@ class Aggregate extends ViewableData {
|
|||||||
Deprecation::notice('4.0', 'Call aggregate methods on a DataList directly instead. In templates'
|
Deprecation::notice('4.0', 'Call aggregate methods on a DataList directly instead. In templates'
|
||||||
. ' an example of the new syntax is <% cached List(Member).max(LastEdited) %> instead'
|
. ' an example of the new syntax is <% cached List(Member).max(LastEdited) %> instead'
|
||||||
. ' (check partial-caching.md documentation for more details.)');
|
. ' (check partial-caching.md documentation for more details.)');
|
||||||
|
self::set_as_file_cache_to_avoid_clearing_entire_cache();
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->filter = $filter;
|
$this->filter = $filter;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
Loading…
Reference in New Issue
Block a user