Bugzilla – Attachment 49029 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: Add a L1 cache for sysprefs
Bug-11998-Add-a-L1-cache-for-sysprefs.patch (text/plain), 3.08 KB, created by
Tomás Cohen Arazi (tcohen)
on 2016-03-11 14:01:12 UTC
(
hide
)
Description:
Bug 11998: Add a L1 cache for sysprefs
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2016-03-11 14:01:12 UTC
Size:
3.08 KB
patch
obsolete
>From 1eb5ac8d8bd417536cb8cb3bdbcb0cd20676ea05 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 10 Mar 2016 08:55:27 +0000 >Subject: [PATCH] Bug 11998: Add a L1 cache for sysprefs > >Accessing to the cache for each call to C4::Context->preference might >have an impact on performances. >To avoid that this patch introduces a L1 cache (simple hashref). It will >be populated by accessing the L2 cache (Koha::Cache). >If a pref is retrieved 10x, the first one will get the value from the L2 >cache, then the L1 cache will be check. >To do so we will need to clear the L1 cache every time a page is loaded. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar> >--- > C4/Context.pm | 33 ++++++++++++++++++++++++++------- > 1 file changed, 26 insertions(+), 7 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 6811e32..bae5f12 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -505,6 +505,7 @@ with this method. > =cut > > my $syspref_cache = Koha::Cache->get_instance(); >+my %syspref_L1_cache; > my $use_syspref_cache = 1; > sub preference { > my $self = shift; >@@ -512,13 +513,16 @@ sub preference { > > $var = lc $var; > >+ # Return the value if the var has already been accessed >+ if ($use_syspref_cache && exists $syspref_L1_cache{$var}) { >+ return $syspref_L1_cache{$var}; >+ } >+ > my $cached_var = $use_syspref_cache > ? $syspref_cache->get_from_cache("syspref_$var") > : undef; > return $cached_var if defined $cached_var; > >- my $dbh = C4::Context->dbh or return 0; >- > my $value; > if ( defined $ENV{"OVERRIDE_SYSPREF_$var"} ) { > $value = $ENV{"OVERRIDE_SYSPREF_$var"}; >@@ -528,7 +532,10 @@ sub preference { > $value = $syspref ? $syspref->value() : undef; > } > >- $syspref_cache->set_in_cache("syspref_$var", $value) if $use_syspref_cache; >+ if ( $use_syspref_cache ) { >+ $syspref_cache->set_in_cache("syspref_$var", $value); >+ $syspref_L1_cache{$var} = $value; >+ } > return $value; > } > >@@ -581,7 +588,13 @@ will not be seen by this process. > =cut > > sub clear_syspref_cache { >- $syspref_cache->flush_all if $use_syspref_cache; >+ return unless $use_syspref_cache; >+ $syspref_cache->flush_all; >+ clear_syspref_L1_cache() >+} >+ >+sub clear_syspref_L1_cache { >+ %syspref_L1_cache = (); > } > > =head2 set_preference >@@ -632,8 +645,10 @@ sub set_preference { > )->store(); > } > >- $syspref_cache->set_in_cache( "syspref_$variable", $value ) >- if $use_syspref_cache; >+ if ( $use_syspref_cache ) { >+ $syspref_cache->set_in_cache( "syspref_$variable", $value ); >+ $syspref_L1_cache{$variable} = $value; >+ } > > return $syspref; > } >@@ -652,7 +667,11 @@ sub delete_preference { > my ( $self, $var ) = @_; > > if ( Koha::Config::SysPrefs->find( $var )->delete ) { >- $syspref_cache->clear_from_cache("syspref_$var") if $use_syspref_cache; >+ if ( $use_syspref_cache ) { >+ $syspref_cache->clear_from_cache("syspref_$var"); >+ delete $syspref_L1_cache{$var}; >+ } >+ > return 1; > } > return 0; >-- >2.7.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