Skip to content

Commit

Permalink
MDL-65492 cache admin: make it easier to purge a cache repeatedly
Browse files Browse the repository at this point in the history
This can be a big time-saver, e.g. during development.
  • Loading branch information
timhunt committed Jun 12, 2019
1 parent 1baf3af commit 376b7fb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
21 changes: 17 additions & 4 deletions cache/admin.php
Expand Up @@ -208,8 +208,8 @@
break;

case 'purgedefinition': // Purge a specific definition.
$definition = required_param('definition', PARAM_SAFEPATH);
list($component, $area) = explode('/', $definition, 2);
$id = required_param('definition', PARAM_SAFEPATH);
list($component, $area) = explode('/', $id, 2);
$factory = cache_factory::instance();
$definition = $factory->create_definition($component, $area);
if ($definition->has_required_identifiers()) {
Expand All @@ -219,14 +219,27 @@
// Alrighty we can purge just the data belonging to this definition.
cache_helper::purge_by_definition($component, $area);
}
redirect($PAGE->url, get_string('purgedefinitionsuccess', 'cache'), 5);

$message = get_string('purgexdefinitionsuccess', 'cache', [
'name' => $definition->get_name(),
'component' => $component,
'area' => $area,
]);
$purgeagainlink = html_writer::link(new moodle_url('/cache/admin.php', [
'action' => 'purgedefinition', 'sesskey' => sesskey(), 'definition' => $id]),
get_string('purgeagain', 'cache'));
redirect($PAGE->url, $message . ' ' . $purgeagainlink, 5);
break;

case 'purgestore':
case 'purge': // Purge a store cache.
$store = required_param('store', PARAM_TEXT);
cache_helper::purge_store($store);
redirect($PAGE->url, get_string('purgestoresuccess', 'cache'), 5);
$message = get_string('purgexstoresuccess', 'cache', ['store' => $store]);
$purgeagainlink = html_writer::link(new moodle_url('/cache/admin.php', [
'action' => 'purgestore', 'sesskey' => sesskey(), 'store' => $store]),
get_string('purgeagain', 'cache'));
redirect($PAGE->url, $message . ' ' . $purgeagainlink, 5);
break;

case 'newlockinstance':
Expand Down
9 changes: 7 additions & 2 deletions lang/en/cache.php
Expand Up @@ -141,8 +141,9 @@
$string['pluginsummaries'] = 'Installed cache stores';
$string['privacy:metadata:cachestore'] = 'The Cache subsystem stores data temporarily on behalf of other parts of Moodle. This data is not easily identifiable, and is very short lived. It serves as a cache of data stored elsewhere in Moodle, and should therefore already be handled by those Moodle components.';
$string['purge'] = 'Purge';
$string['purgedefinitionsuccess'] = 'Successfully purged the requested definition.';
$string['purgestoresuccess'] = 'Successfully purged the requested store.';
$string['purgeagain'] = 'Purge again';
$string['purgexdefinitionsuccess'] = 'Successfully purged the "{$a->name}" cache ({$a->component}/{$a->area}).';
$string['purgexstoresuccess'] = 'Successfully purged the "{$a->store}" store.';
$string['requestcount'] = 'Test with {$a} requests';
$string['rescandefinitions'] = 'Rescan definitions';
$string['result'] = 'Result';
Expand Down Expand Up @@ -190,3 +191,7 @@
$string['untestable'] = 'Untestable';
$string['userinputsharingkey'] = 'Custom key for sharing';
$string['userinputsharingkey_help'] = 'Enter your own private key here. When you set up other stores on other sites you wish to share data with make sure you set the exact same key there.';

// Deprecated since Moodle 3.8.
$string['purgedefinitionsuccess'] = 'Successfully purged the requested definition.';
$string['purgestoresuccess'] = 'Successfully purged the requested store.';
2 changes: 2 additions & 0 deletions lang/en/deprecated.txt
Expand Up @@ -158,3 +158,5 @@ backpackbadges,core_badges
nobackpackbadges,core_badges
nobackpackcollections,core_badges
error:nogroups,core_badges
purgedefinitionsuccess,core_cache
purgestoresuccess,core_cache

0 comments on commit 376b7fb

Please sign in to comment.