Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-38165 cache: fixed issues purging peristent caches by event

  • Loading branch information...
commit 3d6dd54ad196af15eb5ac2b27c6b3452c85e2b6e 1 parent 0323e1a
@samhemelryk samhemelryk authored
Showing with 35 additions and 8 deletions.
  1. +24 −0 cache/classes/factory.php
  2. +11 −8 cache/classes/helper.php
View
24 cache/classes/factory.php
@@ -76,6 +76,12 @@ class cache_factory {
protected $cachesfromparams = array();
/**
+ * An array of stores organised by definitions.
+ * @var array
+ */
+ protected $definitionstores = array();
+
+ /**
* An array of instantiated stores.
* @var array
*/
@@ -272,10 +278,28 @@ public function create_store_from_config($name, array $details, cache_definition
// order to address the issues.
$store = $this->stores[$name]->create_clone($details);
$store->initialise($definition);
+ $definitionid = $definition->get_id();
+ if (!isset($this->definitionstores[$definitionid])) {
+ $this->definitionstores[$definitionid] = array();
+ }
+ $this->definitionstores[$definitionid][] = $store;
return $store;
}
/**
+ * Returns an array of cache stores that have been initialised for use in definitions.
+ * @param cache_definition $definition
+ * @return array
+ */
+ public function get_store_instances_in_use(cache_definition $definition) {
+ $id = $definition->get_id();
+ if (!isset($this->definitionstores[$id])) {
+ return array();
+ }
+ return $this->definitionstores[$id];
+ }
+
+ /**
* Creates a cache config instance with the ability to write if required.
*
* @param bool $writer If set to true an instance that can update the configuration will be returned.
View
19 cache/classes/helper.php
@@ -312,15 +312,18 @@ public static function purge_by_event($event) {
foreach ($instance->get_definitions() as $name => $definitionarr) {
$definition = cache_definition::load($name, $definitionarr);
if ($definition->invalidates_on_event($event)) {
- // Create the cache.
- $cache = $factory->create_cache($definition);
- // Initialise, in case of a store.
- if ($cache instanceof cache_store) {
- $cache->initialise($definition);
+ // Check if this definition would result in a persistent loader being in use.
+ if ($definition->should_be_persistent()) {
+ // There may be a persistent cache loader. Lets purge that first so that any persistent data is removed.
+ $cache = $factory->create_cache_from_definition($definition->get_component(), $definition->get_area());
+ $cache->purge();
+ }
+ // Get all of the store instances that are in use for this store.
+ $stores = $factory->get_store_instances_in_use($definition);
+ foreach ($stores as $store) {
+ // Purge each store individually.
+ $store->purge();
}
- // Purge the cache.
- $cache->purge();
-
// We need to flag the event in the "Event invalidation" cache if it hasn't already happened.
if ($invalidationeventset === false) {
// Get the event invalidation cache.

0 comments on commit 3d6dd54

Please sign in to comment.
Something went wrong with that request. Please try again.