Bugzilla – Attachment 36523 Details for
Bug 11998
Syspref caching issues
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11998 - timeout for syspref caching
Bug-11998---timeout-for-syspref-caching.patch (text/plain), 2.18 KB, created by
Robin Sheat
on 2015-03-05 04:45:30 UTC
(
hide
)
Description:
Bug 11998 - timeout for syspref caching
Filename:
MIME Type:
Creator:
Robin Sheat
Created:
2015-03-05 04:45:30 UTC
Size:
2.18 KB
patch
obsolete
>From 759c5c4298a4d04ab2aedbd730b7431ec22f2cd6 Mon Sep 17 00:00:00 2001 >From: Robin Sheat <robin@catalyst.net.nz> >Date: Wed, 26 Mar 2014 19:07:04 +1300 >Subject: [PATCH] Bug 11998 - timeout for syspref caching > >This adds a 30 second timeout for syspref caching so that when run under >plack, you don't end up with different workers having different ideas of >what the sysprefs are for too long. > >Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com> >--- > C4/Context.pm | 22 +++++++++++++--------- > 1 file changed, 13 insertions(+), 9 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index cc93af4..10a1a33 100644 >--- a/C4/Context.pm >+++ b/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; > } >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11998
:
26575
|
26621
|
26714
|
26716
|
26717
|
27382
|
31801
|
31802
|
32870
|
32871
|
32872
|
32873
|
32874
|
33183
|
33447
|
33670
|
33671
|
33685
|
33724
|
33725
|
33746
|
33829
|
33940
|
36523
|
36524
|
36525
|
36526
|
36527
|
36528
|
36529
|
36530
|
36531
|
36532
|
36533
|
36534
|
36571
|
36583
|
36584
|
36585
|
36586
|
36587
|
36588
|
36589
|
36590
|
36591
|
36592
|
36593
|
36594
|
36595
|
48640
|
48652
|
48655
|
48687
|
48688
|
48727
|
48758
|
48928
|
48929
|
48930
|
48931
|
48932
|
48933
|
48934
|
48935
|
48936
|
48961
|
49022
|
49023
|
49024
|
49025
|
49026
|
49027
|
49028
|
49029
|
49030
|
49100
|
49101
|
49102
|
49103
|
49104
|
49105
|
49106
|
49107
|
49108