From cbd38632e8b24700fb1880e0fe15b2c59f9a81a1 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Sun, 30 Sep 2018 11:14:09 +0200 Subject: [PATCH] Bug 20582: Fix memory cache flush Cache flush should be in around_action hook instead of before_dispatch Otherwise it is flushed before every request (even static files requests) Also, make sure the Cache::Memory cache is really flushed (not only L1 cache) --- Koha/App/Koha.pm | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Koha/App/Koha.pm b/Koha/App/Koha.pm index 6e47272a81..529da44247 100644 --- a/Koha/App/Koha.pm +++ b/Koha/App/Koha.pm @@ -22,6 +22,7 @@ sub startup { $self->plugin('RESTV1'); $self->hook(before_dispatch => \&_before_dispatch); + $self->hook(around_action => \&_around_action); # Everything after this comment is only needed to use Mojolicious # controllers. @@ -55,9 +56,26 @@ sub _before_dispatch { $c->req->url->parse($url); - # Flush caches before every request - Koha::Caches->flush_L1_caches(); +} + +sub _around_action { + my ($next, $c, $action, $last) = @_; + + # Flush memory caches before every request + my $caches = $Koha::Caches::singleton_caches; + if ($caches) { + foreach my $key (keys %$caches) { + my $cache = $caches->{$key}; + if (ref $cache->{cache} eq 'Cache::Memory') { + $cache->flush_all; + } + $cache->flush_L1_cache; + } + } + $Koha::Caches::singleton_caches = {}; Koha::Cache::Memory::Lite->flush(); + + return $next->(); } 1; -- 2.17.1