MDL-45584 cache: Make identifiers part of the cache creation.
It is now safe to cache a reference to a cache and expect consistent results. Changing identifiers altered cache results where a reference was held to the cache. Identifiers have been set to be cached with identifiers included so the caches are separate. As a consequence of this it was identified that invalidation events and identifiers don't easily work together as an event can't determine which identifiers should be used for cache invalidation. So invalidation events have been made incompatible with identifiers being set. No core code used this combination as it's not possible to understand any expected behaviour. Event invalidation for application and session caches was centralised to the same location. The only difference was the name of the lastinvalidation variable. This improves support and consistency of invalidation code.
This commit is contained in:
committed by
Mark Nelson
parent
0f59b6dd75
commit
f3789f2fb3
Vendored
+14
-10
@@ -188,7 +188,9 @@ class core_cache_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests set_identifiers resets identifiers and static cache
|
||||
* Tests set_identifiers fails post cache creation.
|
||||
*
|
||||
* set_identifiers cannot be called after initial cache instantiation, as you need to create a difference cache.
|
||||
*/
|
||||
public function test_set_identifiers() {
|
||||
$instance = cache_config_testing::instance();
|
||||
@@ -204,16 +206,8 @@ class core_cache_testcase extends advanced_testcase {
|
||||
$this->assertTrue($cache->set('contest', 'test data 1'));
|
||||
$this->assertEquals('test data 1', $cache->get('contest'));
|
||||
|
||||
$this->expectException('coding_exception');
|
||||
$cache->set_identifiers(array());
|
||||
$this->assertFalse($cache->get('contest'));
|
||||
$this->assertTrue($cache->set('contest', 'empty ident'));
|
||||
$this->assertEquals('empty ident', $cache->get('contest'));
|
||||
|
||||
$cache->set_identifiers(array('area'));
|
||||
$this->assertEquals('test data 1', $cache->get('contest'));
|
||||
|
||||
$cache->set_identifiers(array());
|
||||
$this->assertEquals('empty ident', $cache->get('contest'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2022,6 +2016,16 @@ class core_cache_testcase extends advanced_testcase {
|
||||
$this->assertEquals('b', $returnedinstance2->name);
|
||||
}
|
||||
|
||||
public function test_identifiers_have_separate_caches() {
|
||||
$cachepg = cache::make('core', 'databasemeta', array('dbfamily' => 'pgsql'));
|
||||
$cachepg->set(1, 'here');
|
||||
$cachemy = cache::make('core', 'databasemeta', array('dbfamily' => 'mysql'));
|
||||
$cachemy->set(2, 'there');
|
||||
$this->assertEquals('here', $cachepg->get(1));
|
||||
$this->assertEquals('there', $cachemy->get(2));
|
||||
$this->assertFalse($cachemy->get(1));
|
||||
}
|
||||
|
||||
public function test_performance_debug() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
Reference in New Issue
Block a user