Skip to content

Commit

Permalink
MDL-59427 MUC: cache_helper::purge_all should reset adhoc caches
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed Jun 30, 2017
1 parent 5a651b4 commit 4998d3a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cache/classes/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,15 @@ public function get_caches_in_use() {
return $this->cachesfromdefinitions;
}

/**
* Gets all adhoc caches that have been used within this request.
*
* @return cache_store[] Caches currently in use
*/
public function get_adhoc_caches_in_use() {
return $this->cachesfromparams;
}

/**
* Creates a cache config instance with the ability to write if required.
*
Expand Down
3 changes: 3 additions & 0 deletions cache/classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ public static function purge_all($usewriter = false) {
foreach ($config->get_all_stores() as $store) {
self::purge_store($store['name'], $config);
}
foreach ($factory->get_adhoc_caches_in_use() as $cache) {
$cache->purge();
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions cache/tests/cache_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,16 @@ public function test_purge_routines() {
}
}

/**
* Tests that ad-hoc caches are correctly purged with a purge_all call.
*/
public function test_purge_all_with_adhoc_caches() {
$cache = \cache::make_from_params(\cache_store::MODE_REQUEST, 'core_cache', 'test');
$cache->set('test', 123);
cache_helper::purge_all();
$this->assertFalse($cache->get('test'));
}

/**
* Test that the default stores all support searching.
*/
Expand Down

0 comments on commit 4998d3a

Please sign in to comment.