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
+8 -3
View File
@@ -229,7 +229,8 @@ class cache_helper {
/**
* Invalidates a given set of keys by means of an event.
*
* @todo add support for identifiers to be supplied and utilised.
* Events cannot determine what identifiers might need to be cleared. Event based purge and invalidation
* are only supported on caches without identifiers.
*
* @param string $event
* @param array $keys
@@ -292,8 +293,9 @@ class cache_helper {
if ($cache instanceof cache_store) {
$factory = cache_factory::instance();
$definition = $factory->create_definition($component, $area, null);
$definition->set_identifiers($identifiers);
$cache->initialise($definition);
$cacheddefinition = clone $definition;
$cacheddefinition->set_identifiers($identifiers);
$cache->initialise($cacheddefinition);
}
// Purge baby, purge.
$cache->purge();
@@ -303,6 +305,9 @@ class cache_helper {
/**
* Purges a cache of all information on a given event.
*
* Events cannot determine what identifiers might need to be cleared. Event based purge and invalidation
* are only supported on caches without identifiers.
*
* @param string $event
*/
public static function purge_by_event($event) {