Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-36512 purge_by_*() must initialise the cache implementing a store.

Indeed, given the current stores implementation, purge will not take effect in case of a file store.
  • Loading branch information...
commit 942be4a57455b3718999c7389d5d0e6baccf06b4 1 parent fb8305d
@scara scara authored
Showing with 16 additions and 1 deletion.
  1. +16 −1 cache/classes/helper.php
View
17 cache/classes/helper.php
@@ -270,6 +270,8 @@ public static function invalidate_by_event($event, array $keys) {
/**
* Purges the cache for a specific definition.
*
+ * @todo MDL-36660: Change the signature: $aggregate must be added.
+ *
* @param string $component
* @param string $area
* @param array $identifiers
@@ -278,6 +280,14 @@ public static function invalidate_by_event($event, array $keys) {
public static function purge_by_definition($component, $area, array $identifiers = array()) {
// Create the cache.
$cache = cache::make($component, $area, $identifiers);
+ // Initialise, in case of a store.
+ if ($cache instanceof cache_store) {
+ $factory = cache_factory::instance();
+ // TODO MDL-36660: Providing $aggregate is required for purging purposes: $definition->get_id()
+ $definition = $factory->create_definition($component, $area, null);
+ $definition->set_identifiers($identifiers);
+ $cache->initialise($definition);
+ }
// Purge baby, purge.
$cache->purge();
return true;
@@ -295,8 +305,13 @@ 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)) {
- // Purge the cache.
+ // Create the cache.
$cache = $factory->create_cache($definition);
+ // Initialise, in case of a store.
+ if ($cache instanceof cache_store) {
+ $cache->initialise($definition);
+ }
+ // Purge the cache.
$cache->purge();
// We need to flag the event in the "Event invalidation" cache if it hasn't already happened.
Please sign in to comment.
Something went wrong with that request. Please try again.