Merge branch 'MDL-59427-master' of https://github.com/sammarshallou/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2017-07-04 19:44:07 +02:00
commit f75b93c9d3
3 changed files with 22 additions and 0 deletions

View File

@ -335,6 +335,15 @@ class cache_factory {
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.
*

View File

@ -484,6 +484,9 @@ class cache_helper {
foreach ($config->get_all_stores() as $store) {
self::purge_store($store['name'], $config);
}
foreach ($factory->get_adhoc_caches_in_use() as $cache) {
$cache->purge();
}
}
/**

View File

@ -1730,6 +1730,16 @@ class core_cache_testcase extends advanced_testcase {
}
}
/**
* 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.
*/