@@ -, +, @@ --- C4/Context.pm | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) --- a/C4/Context.pm +++ a/C4/Context.pm @@ -534,18 +534,22 @@ with this method. =cut -# FIXME: running this under mod_perl will require a means of -# flushing the caching mechanism. - -my %sysprefs; +my %syspref_cache; my $use_syspref_cache = 1; sub preference { my $self = shift; my $var = shift; # The system preference to return - if ($use_syspref_cache && exists $sysprefs{lc $var}) { - return $sysprefs{lc $var}; + # We cache for 30 seconds, after that sysprefs are expired from the cache. + # This is for persistent environments like Plack. + my $now = time; + my $cache_oldest = $now - 30; + if ($use_syspref_cache && exists $syspref_cache{lc $var}) { + # The cache contains an arrayref, first entry is the time it was + # stored, the second is the value. + my $cached_value = $syspref_cache{lc $var}; + return $cached_value->[1] if ($cached_value->[0] > $cache_oldest); } my $dbh = C4::Context->dbh or return 0; @@ -564,7 +568,7 @@ sub preference { $value = $dbh->selectrow_array( $sql, {}, lc $var ); } - $sysprefs{lc $var} = $value; + $syspref_cache{lc $var} = [$now, $value]; return $value; } @@ -615,7 +619,7 @@ will not be seen by this process. =cut sub clear_syspref_cache { - %sysprefs = (); + %syspref_cache= (); } =head2 set_preference @@ -646,7 +650,7 @@ sub set_preference { " ); if($sth->execute( $var, $value )) { - $sysprefs{$var} = $value; + $syspref_cache{$var} = [time, $value]; } $sth->finish; } --