Skip to content

Commit

Permalink
MDL-38165 cache: fixed issues purging peristent caches by event
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Feb 28, 2013
1 parent 0323e1a commit 3d6dd54
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
24 changes: 24 additions & 0 deletions cache/classes/factory.php
Expand Up @@ -75,6 +75,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
Expand Down Expand Up @@ -272,9 +278,27 @@ 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.
*
Expand Down
19 changes: 11 additions & 8 deletions cache/classes/helper.php
Expand Up @@ -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.
Expand Down

0 comments on commit 3d6dd54

Please sign in to comment.