From 28c3d8a100d810dcdafb99ac06bc218b0b8832da 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 Content-Type: text/plain; charset="utf-8" --- C4/Auth.pm | 17 ++++------------- C4/Biblio.pm | 11 ++++------- C4/Context.pm | 25 +++++++++++++++++++++++++ C4/Languages.pm | 14 ++++---------- etc/koha-conf.xml | 2 -- 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index e360e10..7cc3be1 100755 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -35,7 +35,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 } @@ -61,16 +61,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 @@ -1422,8 +1413,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 ac78ae3..74a7483 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -137,16 +137,13 @@ 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', - }; - memoize_memcached( 'GetMarcStructure', memcached => $memcached, expire_time => 600 ); #cache for 10 minutes + memoize_memcached( 'GetMarcStructure', + memcached => C4::Context->memcached, + expire_time => 600 ); #cache for 10 minutes } }; diff --git a/C4/Context.pm b/C4/Context.pm index c2ed85c..d6c2e9a 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -253,6 +253,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 091d3bb..0cc288e 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -26,19 +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', - }; - - memoize_memcached('getTranslatedLanguages', memcached => $memcached, expire_time => 600); #cache for 10 minutes - memoize_memcached('getFrameworkLanguages' , memcached => $memcached, expire_time => 600); - memoize_memcached('getAllLanguages', memcached => $memcached, expire_time => 600); + memoize_memcached('getTranslatedLanguages', memcached => C4::Context->memcached, expire_time => 600); #cache for 10 minutes + memoize_memcached('getFrameworkLanguages' , memcached => C4::Context->memcached, expire_time => 600); + memoize_memcached('getAllLanguages', memcached => C4::Context->memcached, expire_time => 600); } }; diff --git a/etc/koha-conf.xml b/etc/koha-conf.xml index 686a15b..f5e2c0f 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__ -- 1.7.5.4