[Koha-patches] [memcached 2/2] Clearing Cached Data When System Preferences Are Changed

John Beppu john.beppu at liblime.com
Wed Feb 4 10:35:32 CET 2009


- C4::Context->clear_syspref_cache can now optionally take a
  syspref variable name.  This makes it clear just that one
  variable from the cache rather than clearing the entire cache.

  If no parameters are passed, the entire cache is cleared just
  like it did before.

- more documenation

- admin/systempreferences.pl now makes use of
  C4::Context->clear_syspref_cache whenever a syspref is changed.
---
 C4/Context.pm              |   32 +++++++++++++++++++-------------
 admin/systempreferences.pl |    4 +++-
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/C4/Context.pm b/C4/Context.pm
index 1f321e0..bb12591 100644
--- a/C4/Context.pm
+++ b/C4/Context.pm
@@ -462,13 +462,13 @@ F<koha-conf.xml> like this:
 B<memcachedserver> should be a comma separated list of memcached servers to
 use.
 
-Each namespace you intend to use should have a tag named like
+Each namespace you intend to use should be defined within a tag named like:
 B<memcached${name}namespace>.  In the example above, the C<preference> and
 C<misc> namespaces have been defined.
 
-B<IMPORTANT>:  Each koha installation on a server should define its own set of
-namespaces in order to prevent the data for one koha installation from
-interfering with another koha installation.
+B<IMPORTANT>:  When running multiple koha instances on a single server, each
+koha instance should define its own set of namespaces in order to prevent the
+data for one koha installation from interfering with another koha installation.
 
 =cut
 
@@ -545,24 +545,30 @@ sub boolean_preference ($) {
     return defined($it)? C4::Boolean::true_p($it): undef;
 }
 
-sub set_preference {
-    my ($class, $var, $value) = @_;
-}
-
 =item clear_syspref_cache
 
   C4::Context->clear_syspref_cache();
+  C4::Context->clear_syspref_cache($variable);
+
+This method cleans the internal cache of sysprefs. Please call this method if
+you update the systempreferences table. Otherwise, your new changes
+will not be seen by this process.
 
-  cleans the internal cache of sysprefs. Please call this method if
-  you update the systempreferences table. Otherwise, your new changes
-  will not be seen by this process.
+This method also takes an optional argument if you want to delete just one
+variable from the cache instead of deleting everything.
 
 =cut
 
 sub clear_syspref_cache {
-    %sysprefs = ();
+    my ($class, $var) = @_;
     my $memd = C4::Context->memcached('preference');
-    $memd->flush_all if $memd;
+    if ($var) {
+        delete $sysprefs{$var};
+        $memd->delete($var) if $memd;
+    } else {
+        %sysprefs = ();
+        $memd->flush_all if $memd;
+    }
 }
 
 # AUTOLOAD
diff --git a/admin/systempreferences.pl b/admin/systempreferences.pl
index d323a51..7770f0a 100755
--- a/admin/systempreferences.pl
+++ b/admin/systempreferences.pl
@@ -572,7 +572,7 @@ if ( $op eq 'update_and_reedit' ) {
         }
     }
     $sth->finish;
-
+    C4::Context->clear_syspref_cache($input->param('variable'));
 }
 
 ################## ADD_FORM ##################################
@@ -641,6 +641,7 @@ if ( $op eq 'add_form' ) {
         }
     }
     $sth->finish;
+    C4::Context->clear_syspref_cache($input->param('variable'));
     print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
     exit;
 ################## DELETE_CONFIRM ##################################
@@ -666,6 +667,7 @@ if ( $op eq 'add_form' ) {
     my $logstring = $searchfield . " | " . $Tvalue;
     logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
     $sth->finish;
+    C4::Context->clear_syspref_cache($searchfield);
 
     # END $OP eq DELETE_CONFIRMED
 ################## DEFAULT ##################################
-- 
1.6.0.3




More information about the Koha-patches mailing list