mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
Merge branch 'm24_MDL-36512_Purging_file_cachestore_does_not_purge_anything' of https://github.com/scara/moodle
This commit is contained in:
commit
542f68b022
55
cache/classes/config.php
vendored
55
cache/classes/config.php
vendored
@ -344,6 +344,61 @@ class cache_config {
|
||||
return $this->configdefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the definitions mapped into the given store name.
|
||||
*
|
||||
* @param string $storename
|
||||
* @return array Associative array of definitions, id=>definition
|
||||
*/
|
||||
public static function get_definitions_by_store($storename) {
|
||||
$definitions = array();
|
||||
|
||||
$config = cache_config::instance();
|
||||
$stores = $config->get_all_stores();
|
||||
if (!array_key_exists($storename, $stores)) {
|
||||
// The store does not exist.
|
||||
return false;
|
||||
}
|
||||
|
||||
$defmappings = $config->get_definition_mappings();
|
||||
// Create an associative array for the definition mappings.
|
||||
$thedefmappings = array();
|
||||
foreach ($defmappings as $defmapping) {
|
||||
$thedefmappings[$defmapping['definition']] = $defmapping;
|
||||
}
|
||||
|
||||
// Search for matches in default mappings.
|
||||
$defs = $config->get_definitions();
|
||||
foreach($config->get_mode_mappings() as $modemapping) {
|
||||
if ($modemapping['store'] !== $storename) {
|
||||
continue;
|
||||
}
|
||||
foreach($defs as $id => $definition) {
|
||||
if ($definition['mode'] !== $modemapping['mode']) {
|
||||
continue;
|
||||
}
|
||||
// Exclude custom definitions mapping: they will be managed few lines below.
|
||||
if (array_key_exists($id, $thedefmappings)) {
|
||||
continue;
|
||||
}
|
||||
$definitions[$id] = $definition;
|
||||
}
|
||||
}
|
||||
|
||||
// Search for matches in the custom definitions mapping
|
||||
foreach ($defmappings as $defmapping) {
|
||||
if ($defmapping['store'] !== $storename) {
|
||||
continue;
|
||||
}
|
||||
$definition = $config->get_definition_by_id($defmapping['definition']);
|
||||
if ($definition) {
|
||||
$definitions[$defmapping['definition']] = $definition;
|
||||
}
|
||||
}
|
||||
|
||||
return $definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the stores that are suitable for the given mode and requirements.
|
||||
*
|
||||
|
63
cache/classes/helper.php
vendored
63
cache/classes/helper.php
vendored
@ -270,6 +270,8 @@ class cache_helper {
|
||||
/**
|
||||
* 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 @@ class cache_helper {
|
||||
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 @@ class cache_helper {
|
||||
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.
|
||||
@ -389,16 +404,9 @@ class cache_helper {
|
||||
*/
|
||||
public static function purge_all() {
|
||||
$config = cache_config::instance();
|
||||
$stores = $config->get_all_stores();
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'core', 'cache_purge');
|
||||
foreach ($stores as $store) {
|
||||
$class = $store['class'];
|
||||
$instance = new $class($store['name'], $store['configuration']);
|
||||
if (!$instance->is_ready()) {
|
||||
continue;
|
||||
}
|
||||
$instance->initialise($definition);
|
||||
$instance->purge();
|
||||
|
||||
foreach ($config->get_all_stores() as $store) {
|
||||
self::purge_store($store['name']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -410,21 +418,32 @@ class cache_helper {
|
||||
*/
|
||||
public static function purge_store($storename) {
|
||||
$config = cache_config::instance();
|
||||
foreach ($config->get_all_stores() as $store) {
|
||||
if ($store['name'] !== $storename) {
|
||||
continue;
|
||||
}
|
||||
$class = $store['class'];
|
||||
|
||||
$stores = $config->get_all_stores();
|
||||
if (!array_key_exists($storename, $stores)) {
|
||||
// The store does not exist.
|
||||
return false;
|
||||
}
|
||||
|
||||
$store = $stores[$storename];
|
||||
$class = $store['class'];
|
||||
|
||||
// Found the store: is it ready?
|
||||
$instance = new $class($store['name'], $store['configuration']);
|
||||
if (!$instance->is_ready()) {
|
||||
unset($instance);
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($config->get_definitions_by_store($storename) as $id => $definition) {
|
||||
$definition = cache_definition::load($id, $definition);
|
||||
$instance = new $class($store['name'], $store['configuration']);
|
||||
if (!$instance->is_ready()) {
|
||||
continue;
|
||||
}
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'core', 'cache_purge');
|
||||
$instance->initialise($definition);
|
||||
$instance->purge();
|
||||
return true;
|
||||
unset($instance);
|
||||
}
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user