Permalink
Browse files

feature(cache): introducing a generic function to reset all caches

With the introduction of more cache types there was no way te easily
reset them all. This new function triggers an event so every cache can
reset as needed.
  • Loading branch information...
jeabakker authored and mrclay committed Apr 10, 2015
1 parent 19b9388 commit f526c479fd99f50cab008f5fc0b3c18069e83064
@@ -46,8 +46,7 @@
// don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regenerate as needed
elgg_invalidate_simplecache();
elgg_reset_system_cache();
elgg_flush_caches();
if (count($activated_guids) === 1) {
$url = 'admin/plugins';
@@ -54,7 +54,6 @@
// don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regnerate as needed
elgg_invalidate_simplecache();
elgg_reset_system_cache();
elgg_flush_caches();
forward(REFERER);
@@ -36,8 +36,7 @@
// don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regnerate as needed
elgg_invalidate_simplecache();
elgg_reset_system_cache();
elgg_flush_caches();
if (count($plugin_guids) == 1) {
$url = 'admin/plugins';
@@ -27,7 +27,6 @@
// don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regnerate as needed
elgg_invalidate_simplecache();
elgg_reset_system_cache();
elgg_flush_caches();
forward(REFERER);
@@ -33,7 +33,6 @@
// don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regnerate as needed
elgg_invalidate_simplecache();
elgg_reset_system_cache();
elgg_flush_caches();
forward(REFERER);
@@ -3,8 +3,7 @@
* Flush all the caches
*/
elgg_invalidate_simplecache();
elgg_reset_system_cache();
elgg_flush_caches();
_elgg_services()->autoloadManager->deleteCache();
system_message(elgg_echo('admin:cache:flushed'));
@@ -61,6 +61,9 @@ System events
**init:cookie, <name>**
Return false to override setting a cookie.
**cache:flush, system**
Reset internal and external caches. For example it resets system_cache and simplecache, but also PHP opcode caches (APC, OPCache, WinCache).
User events
===========
@@ -59,8 +59,7 @@ public function run() {
}
_elgg_services()->events->trigger('upgrade', 'system', null);
elgg_invalidate_simplecache();
elgg_reset_system_cache();
elgg_flush_caches();
$this->releaseUpgradeMutex();
View
@@ -221,6 +221,16 @@ function elgg_invalidate_simplecache() {
_elgg_services()->simpleCache->invalidate();
}
/**
* Flush all the registered caches
*
* @return void
* @since 1.11
*/
function elgg_flush_caches() {
_elgg_services()->events->trigger('cache:flush', 'system');
}
/**
* Initializes the simplecache lastcache variable and creates system cache files
* when appropriate.
@@ -234,4 +244,8 @@ function _elgg_cache_init() {
return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
$events->registerHandler('ready', 'system', '_elgg_cache_init');
// register plugin hooks for cache reset
$events->registerHandler('cache:flush', 'system', 'elgg_reset_system_cache');
$events->registerHandler('cache:flush', 'system', 'elgg_invalidate_simplecache');
};

0 comments on commit f526c47

Please sign in to comment.