From f027b5eaf56e33d2f74ff4684085c094641b4384 Mon Sep 17 00:00:00 2001 From: Nicolaas Date: Fri, 27 Jan 2017 07:51:42 +1300 Subject: [PATCH] MINOR: stop Aggregate clear cache on DataObject::write() see: https://github.com/silverstripe/silverstripe-framework/issues/6383 for details --- model/Aggregate.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/model/Aggregate.php b/model/Aggregate.php index 621e60978..c18681ba3 100644 --- a/model/Aggregate.php +++ b/model/Aggregate.php @@ -41,9 +41,25 @@ class Aggregate extends ViewableData { /** Build & cache the cache object */ 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')); } + /** + * 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. * {@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' . ' an example of the new syntax is <% cached List(Member).max(LastEdited) %> instead' . ' (check partial-caching.md documentation for more details.)'); + self::set_as_file_cache_to_avoid_clearing_entire_cache(); $this->type = $type; $this->filter = $filter; parent::__construct();