From 52afe06ddd222fcd143bf34ba01daf01ba56674e Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 30 Dec 2011 09:10:36 -0300 Subject: [PATCH] Bug 6193 - Follow up: use SetEnv and remove memcached from koha-conf.xml Signed-off-by: Jared Camins-Esakov Confirmed that memcached is still being used after the memcached configuration in koha-conf.xml was removed, and the following two lines were added to both virtual hosts in koha-httpd.conf: SetEnv MEMCACHED_SERVERS "127.0.0.1:11211" SetEnv MEMCACHED_NAMESPACE "KOHA" --- C4/Auth.pm | 17 ++++------------- C4/Biblio.pm | 11 +++-------- C4/Context.pm | 26 ++++++++++++++++++++++++++ C4/Languages.pm | 15 ++++----------- etc/koha-conf.xml | 2 -- 5 files changed, 37 insertions(+), 34 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index a855818aa1..ccb2c15000 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -33,7 +33,7 @@ use POSIX qw/strftime/; use List::MoreUtils qw/ any /; # use utf8; -use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout $servers $memcached); +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout); BEGIN { sub psgi_env { any { /^psgi\./ } keys %ENV } @@ -59,16 +59,7 @@ BEGIN { if ($cas) { import C4::Auth_with_cas qw(check_api_auth_cas checkpw_cas login_cas logout_cas login_cas_url); } - $servers = C4::Context->config('memcached_servers'); - if ($servers) { - require Cache::Memcached; - $memcached = Cache::Memcached->new({ - servers => [ $servers ], - debug => 0, - compress_threshold => 10_000, - namespace => C4::Context->config('memcached_namespace') || 'koha', - }); - } + } =head1 NAME @@ -1424,8 +1415,8 @@ sub get_session { elsif ($storage_method eq 'Pg') { $session = new CGI::Session("driver:PostgreSQL;serializer:yaml;id:md5", $sessionID, {Handle=>$dbh}); } - elsif ($storage_method eq 'memcached' && $servers){ - $session = new CGI::Session("driver:memcached;serializer:yaml;id:md5", $sessionID, { Memcached => $memcached } ); + elsif ($storage_method eq 'memcached' && C4::Context->ismemcached){ + $session = new CGI::Session("driver:memcached;serializer:yaml;id:md5", $sessionID, { Memcached => C4::Context->memcached } ); } else { # catch all defaults to tmp should work on all systems diff --git a/C4/Biblio.pm b/C4/Biblio.pm index eafb67bdf9..b3a95b898c 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -132,17 +132,12 @@ BEGIN { } eval { - my $servers = C4::Context->config('memcached_servers'); - if ($servers) { + if (C4::Context->ismemcached) { require Memoize::Memcached; import Memoize::Memcached qw(memoize_memcached); - my $memcached = { - servers => [$servers], - key_prefix => C4::Context->config('memcached_namespace') || 'koha', - expire_time => 600 - }; # cache for 10 mins, if you want to cache for different make a different memcached hash - memoize_memcached( 'GetMarcStructure', memcached => $memcached ); + memoize_memcached( 'GetMarcStructure', + memcached => C4::Context->memcached); } }; diff --git a/C4/Context.pm b/C4/Context.pm index 770973fd1a..53246ec580 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -88,6 +88,7 @@ BEGIN { servers => [ $servers ], debug => 0, compress_threshold => 10_000, + expire_time => 600, namespace => $ENV{'MEMCACHED_NAMESPACE'} || 'koha' }); # Verify memcached available (set a variable and test the output) @@ -253,6 +254,31 @@ sub read_config_file { # Pass argument naming config file to read return $koha; # Return value: ref-to-hash holding the configuration } +=head2 ismemcached + +Returns the value of the $ismemcached variable (0/1) + +=cut + +sub ismemcached { + return $ismemcached; +} + +=head2 memcached + +If $ismemcached is true, returns the $memcache variable. +Returns undef otherwise + +=cut + +sub memcached { + if ($ismemcached) { + return $memcached; + } else { + return undef; + } +} + # db_scheme2dbi # Translates the full text name of a database into de appropiate dbi name # diff --git a/C4/Languages.pm b/C4/Languages.pm index ac5ea551f8..6f269ace46 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -26,20 +26,13 @@ use C4::Context; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); eval { - my $servers = C4::Context->config('memcached_servers'); - if ($servers) { + if (C4::Context->ismemcached) { require Memoize::Memcached; import Memoize::Memcached qw(memoize_memcached); - my $memcached = { - servers => [$servers], - key_prefix => C4::Context->config('memcached_namespace') || 'koha', - expire_time => 600 - }; # cache for 10 mins - - memoize_memcached( 'getTranslatedLanguages', memcached => $memcached ); - memoize_memcached( 'getFrameworkLanguages', memcached => $memcached ); - memoize_memcached( 'getAllLanguages', memcached => $memcached ); + memoize_memcached('getTranslatedLanguages', memcached => C4::Context->memcached); + memoize_memcached('getFrameworkLanguages' , memcached => C4::Context->memcached); + memoize_memcached('getAllLanguages', memcached => C4::Context->memcached); } }; diff --git a/etc/koha-conf.xml b/etc/koha-conf.xml index 686a15b701..f5e2c0ffd6 100644 --- a/etc/koha-conf.xml +++ b/etc/koha-conf.xml @@ -275,7 +275,5 @@ __PAZPAR2_TOGGLE_XML_POST__ http://__PAZPAR2_HOST__:__PAZPAR2_PORT__/search.pz2 __MISC_DIR__/koha-install-log 0 - __MEMCACHED_SERVERS__ - __MEMCACHED_NAMESPACE__ -- 2.39.5