Skip to content

Commit

Permalink
Merge pull request #6570 from sunnysideup/patch-50
Browse files Browse the repository at this point in the history
MINOR: stop Aggregate clear cache on DataObject::write()
  • Loading branch information
Damian Mooyman authored Jan 26, 2017
2 parents c8525c0 + f027b5e commit 8ce8be9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions model/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -76,6 +92,7 @@ public function __construct($type, $filter = '') {
Deprecation::notice('4.0', 'Call aggregate methods on a DataList directly instead. In templates'
. ' an example of the new syntax is &lt% cached List(Member).max(LastEdited) %&gt 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();
Expand Down

0 comments on commit 8ce8be9

Please sign in to comment.