@@ -, +, @@ --- C4/Koha.pm | 15 +++++++++++++-- Koha/Cache.pm | 20 ++++++++++++++++++++ debian/templates/plack.psgi | 2 +- misc/plack/koha.psgi | 2 +- 4 files changed, 35 insertions(+), 4 deletions(-) --- a/C4/Koha.pm +++ a/C4/Koha.pm @@ -1008,6 +1008,13 @@ C<$opac> If set to a true value, displays OPAC descriptions rather than normal o =cut +sub _AddSelectedAuthVal { + my ( $authorised_values, $selected ) = @_; + foreach my $data ( @$authorised_values ) { + $data->{selected} = $selected eq $data->{authorised_value} ? 1 : 0; + } +} + sub GetAuthorisedValues { my ( $category, $opac ) = @_; @@ -1019,7 +1026,10 @@ sub GetAuthorisedValues { "AuthorisedValues-$category-$opac-$branch_limit"; my $cache = Koha::Cache->get_instance(); my $result = $cache->get_from_cache($cache_key); - return $result if $result; + if ($result) { + _AddSelectedAuthVal( $result, $selected ) if defined $selected; + return $result; + } my @results; my $dbh = C4::Context->dbh; @@ -1060,7 +1070,8 @@ sub GetAuthorisedValues { } $sth->finish; - $cache->set_in_cache( $cache_key, \@results, { deepcopy => 1, expiry => 5 } ); + $cache->set_in_cache( $cache_key, \@results ); + _AddSelectedAuthVal( \@results, $selected ); return \@results; } --- a/Koha/Cache.pm +++ a/Koha/Cache.pm @@ -41,6 +41,7 @@ use Carp; use Clone qw( clone ); use Module::Load::Conditional qw(can_load); use Koha::Cache::Object; +use Time::HiRes qw(time); use base qw(Class::Accessor); @@ -48,6 +49,7 @@ __PACKAGE__->mk_ro_accessors( qw( cache memcached_cache fastmmap_cache memory_cache )); our %L1_cache; +our $L1_cache_time; =head2 get_instance @@ -131,6 +133,22 @@ sub new { $class; } +sub flush_L1_if_needed { + my ($self) = @_; + + if ( $self->{cache} ) { + if ( $L1_cache_time ) { + my $upstream_cache_mtime = $self->{cache}->get('upstream_cache_mtime'); + + if ( $upstream_cache_mtime && $upstream_cache_mtime > $L1_cache_time ) { + $self->flush_L1_cache(); + } + } + + $L1_cache_time = time(); + } +} + sub _initialize_memcached { my ($self) = @_; my @servers = @@ -288,6 +306,8 @@ sub set_in_cache { # Set in L1 cache $L1_cache{ $key } = $value; + $self->{$cache}->set( 'upstream_cache_mtime', time() ); + # We consider an expiry of 0 to be inifinite if ( $expiry ) { return $set_sub --- a/debian/templates/plack.psgi +++ a/debian/templates/plack.psgi @@ -44,7 +44,7 @@ use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise *CGI::new = sub { my $q = $old_new->( @_ ); $CGI::PARAM_UTF8 = 1; - Koha::Cache->flush_L1_cache(); + Koha::Cache->flush_L1_if_needed(); return $q; }; } --- a/misc/plack/koha.psgi +++ a/misc/plack/koha.psgi @@ -12,7 +12,7 @@ use CGI qw(-utf8 ); # we will lose -utf8 under plack *CGI::new = sub { my $q = $old_new->( @_ ); $CGI::PARAM_UTF8 = 1; - Koha::Cache->flush_L1_cache(); + Koha::Cache->flush_L1_if_needed(); return $q; }; } --