From c048dda74e5f8637dc0074fb0d92c839be15b7fb Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 7 Mar 2019 15:37:25 -0300 Subject: [PATCH] Bug 22473: Handle config expiration in C4::Context->new - V3 --- C4/Context.pm | 20 +++++++++++++++++++- debian/templates/plack.psgi | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/C4/Context.pm b/C4/Context.pm index 9b3f74dbb2..1e92922560 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -249,7 +249,25 @@ sub new { my $conf_cache = Koha::Caches->get_instance('config'); my $config_from_cache; if ( $conf_cache->cache ) { - $self = $conf_cache->get_from_cache('koha_conf'); + my $last_modification_time_cached = + $conf_cache->get_from_cache('last_modification_time'); + my $last_modification_time = qx{stat --format %Y $conf_fname}; + + # There must be nothing in cache (or the last modification does not exist yet) + unless ($last_modification_time_cached) { + $conf_cache->set_in_cache( 'last_modification_time', + $last_modification_time ); + } + # The config file needs to be reread, it has been changed since the last init of C4::Context + elsif ( $last_modification_time > $last_modification_time_cached ) { + $conf_cache->flush_all; + $conf_cache->set_in_cache( 'last_modification_time', + $last_modification_time ); + } + # We can use the data from the cache + else { + $self = $conf_cache->get_from_cache('koha_conf'); + } } unless ( $self and %$self ) { $self = Koha::Config->read_from_file($conf_fname); diff --git a/debian/templates/plack.psgi b/debian/templates/plack.psgi index 3538b9a5a1..bb2ae6f0f6 100644 --- a/debian/templates/plack.psgi +++ b/debian/templates/plack.psgi @@ -46,6 +46,7 @@ use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise $CGI::PARAM_UTF8 = 1; Koha::Caches->flush_L1_caches(); Koha::Cache::Memory::Lite->flush(); + C4::Context->new; # Any side effects to expect from this? return $q; }; } -- 2.11.0