Bugzilla – Attachment 3926 Details for
Bug 6193
Use memcached cache koha-conf.xml configuration variables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Initial patch
0001-Bug-6193-Use-memcached-cache-koha-conf.xml-configura.patch (text/plain), 5.13 KB, created by
Tomás Cohen Arazi (tcohen)
on 2011-04-14 17:52:40 UTC
(
hide
)
Description:
Initial patch
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2011-04-14 17:52:40 UTC
Size:
5.13 KB
patch
obsolete
>From af8a3648880a297ef812e987d0467e127f810535 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@gmail.com> >Date: Thu, 14 Apr 2011 14:40:21 -0300 >Subject: [PATCH] Bug 6193 - Use memcached cache koha-conf.xml configuration variables >Content-Type: text/plain; charset="utf-8" > >Basically I add some code to Context.pm so it stores koha-conf.xml config vars >in memcached server. It is arguable whether this is an improvement or not, >tests are needed to conclude something about this. > >Error handling was an issue with Cache::Memcached, I tried to do it the >simplest I could. > >Note: As it was pointless to read the xml file to get the memcached >server info for accessing them for retreiving the info in the koha-conf.xml >file... I passed those values through apache's SetEnv. These variables >are set acordingly through the install scripts and commented out if koha >was setup not to use it. >--- > C4/Context.pm | 41 +++++++++++++++++++++++++++++++++++++---- > etc/koha-httpd.conf | 4 ++++ > rewrite-config.PL | 5 +++++ > 3 files changed, 46 insertions(+), 4 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 85d1c18..06c30b5 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -18,7 +18,7 @@ package C4::Context; > > use strict; > use warnings; >-use vars qw($VERSION $AUTOLOAD $context @context_stack); >+use vars qw($VERSION $AUTOLOAD $context @context_stack $servers $memcached $ismemcached); > > BEGIN { > if ($ENV{'HTTP_USER_AGENT'}) { >@@ -78,6 +78,20 @@ BEGIN { > $main::SIG{__DIE__} = \&CGI::Carp::confess; > } > } # else there is no browser to send fatals to! >+ >+ # memcached stuff >+ $servers = $ENV{'MEMCACHED_SERVERS'}; >+ if ($servers) { >+ require Cache::Memcached; >+ $memcached = Cache::Memcached->new({ >+ servers => [ $servers ], >+ debug => 0, >+ compress_threshold => 10_000, >+ namespace => $ENV{'MEMCACHED_NAMESPACE'} || 'koha' >+ }); >+ $ismemcached = $memcached->set('ismemcached','1'); >+ } >+ > $VERSION = '3.00.00.036'; > } > >@@ -229,6 +243,11 @@ Returns undef in case of error. > > sub read_config_file { # Pass argument naming config file to read > my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => ''); >+ >+ if ($ismemcached) { >+ $memcached->set('kohaconf',$koha); >+ } >+ > return $koha; # Return value: ref-to-hash holding the configuration > } > >@@ -274,6 +293,10 @@ Allocates a new context. Initializes the context from the specified > file, which defaults to either the file given by the C<$KOHA_CONF> > environment variable, or F</etc/koha/koha-conf.xml>. > >+It saves the koha-conf.xml values in the declared memcached server(s) >+if currently available and uses those values until them expire and >+re-reads them. >+ > C<&new> does not set this context as the new default context; for > that, use C<&set_context>. > >@@ -308,10 +331,20 @@ sub new { > return undef; > } > } >- # Load the desired config file. >- $self = read_config_file($conf_fname); >- $self->{"config_file"} = $conf_fname; > >+ if ($ismemcached) { >+ # retreive from memcached >+ $self = $memcached->get('kohaconf'); >+ if (not defined $self) { >+ # not in memcached yet >+ $self = read_config_file($conf_fname); >+ } >+ } else { >+ # non-memcached env, read from file >+ $self = read_config_file($conf_fname); >+ } >+ >+ $self->{"config_file"} = $conf_fname; > warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"}); > return undef if !defined($self->{"config"}); > >diff --git a/etc/koha-httpd.conf b/etc/koha-httpd.conf >index bc2b4d8..2c4c208 100644 >--- a/etc/koha-httpd.conf >+++ b/etc/koha-httpd.conf >@@ -16,6 +16,8 @@ > # TransferLog __LOG_DIR__/koha-opac-access_log > SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml" > SetEnv PERL5LIB "__PERL_MODULE_DIR__" >+__MEMCACHED_COMMENTED__ SetEnv MEMCACHED_SERVERS "__MEMCACHED_SERVERS__" >+__MEMCACHED_COMMENTED__ SetEnv MEMCACHED_NAMESPACE "__MEMCACHED_NAMESPACE__" > > <IfModule mod_gzip.c> > mod_gzip_on yes >@@ -106,6 +108,8 @@ > # TransferLog __LOG_DIR__/koha-access_log > SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml" > SetEnv PERL5LIB "__PERL_MODULE_DIR__" >+__MEMCACHED_COMMENTED__ SetEnv MEMCACHED_SERVERS "__MEMCACHED_SERVERS__" >+__MEMCACHED_COMMENTED__ SetEnv MEMCACHED_NAMESPACE "__MEMCACHED_NAMESPACE__" > Options +FollowSymLinks > > ErrorDocument 400 /cgi-bin/koha/errors/400.pl >diff --git a/rewrite-config.PL b/rewrite-config.PL >index 7817f91..765c456 100644 >--- a/rewrite-config.PL >+++ b/rewrite-config.PL >@@ -139,6 +139,7 @@ $prefix = $ENV{'INSTALL_BASE'} || "/usr"; > "__USE_MEMCACHED__" => 'no', > "__MEMCACHED_SERVERS__" => "", > "__MEMCACHED_NAMESPACE__" => "", >+ "__MEMCACHED_COMMENTED__" => "#", > ); > > # Override configuration from the environment >@@ -155,6 +156,10 @@ if ($configuration{'__INSTALL_PAZPAR2__'} eq 'yes') { > $configuration{'__PAZPAR2_TOGGLE_XML_POST__'} = ''; > } > >+if ("__USE_MEMCACHED__" eq 'yes') { >+ $configuration{'__MEMCACHED_COMMENTED__'} => ''; >+} >+ > $fname = $ARGV[0]; > $file = &read_file($fname); > $file =~ s/__.*?__/exists $configuration{$&} ? $configuration{$&} : $&/seg; >-- >1.7.1 >
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 6193
:
3926
|
3927
|
5045
|
5537
|
5559
|
6971
|
7630