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:
Russell Smith
2017-03-02 11:06:17 +08:00
committed by Mark Nelson
parent 0f59b6dd75
commit f3789f2fb3
8 changed files with 131 additions and 127 deletions
+7 -1
View File
@@ -212,6 +212,9 @@ class cache_factory_disabled extends cache_factory {
* @return cache_application|cache_session|cache_request
*/
public function create_cache_from_definition($component, $area, array $identifiers = array(), $unused = null) {
// Regular cache definitions are cached inside create_definition(). This is not the case for disabledlib.php
// definitions as they use load_adhoc(). They are built as a new object on each call.
// We do not need to clone the definition because we know it's new.
$definition = $this->create_definition($component, $area);
$definition->set_identifiers($identifiers);
$cache = $this->create_cache($definition);
@@ -233,7 +236,10 @@ class cache_factory_disabled extends cache_factory {
* @return cache_application|cache_session|cache_request
*/
public function create_cache_from_params($mode, $component, $area, array $identifiers = array(), array $options = array()) {
$definition = cache_definition::load_adhoc($mode, $component, $area);
// Regular cache definitions are cached inside create_definition(). This is not the case for disabledlib.php
// definitions as they use load_adhoc(). They are built as a new object on each call.
// We do not need to clone the definition because we know it's new.
$definition = cache_definition::load_adhoc($mode, $component, $area, $options);
$definition->set_identifiers($identifiers);
$cache = $this->create_cache($definition);
return $cache;