X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;ds=sidebyside;f=C4%2FContext.pm;h=0417c45075341cad9ef1091424e3a364f3202f1a;hb=a334fec190f5efcda731d5ea6b0d72d16ef594b9;hp=7581faa0fbe1242ae117a5e09cc0cc0c04e96985;hpb=7655eaedc124d52ca1f4d17855dc3753abf0802c;p=koha_gimpoz diff --git a/C4/Context.pm b/C4/Context.pm index 7581faa0fb..0417c45075 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,7 +78,24 @@ BEGIN { $main::SIG{__DIE__} = \&CGI::Carp::confess; } } # else there is no browser to send fatals to! - $VERSION = '3.00.00.036'; + + # Check if there are memcached servers set + $servers = $ENV{'MEMCACHED_SERVERS'}; + if ($servers) { + # Load required libraries and create the memcached object + require Cache::Memcached; + $memcached = Cache::Memcached->new({ + 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) + $ismemcached = $memcached->set('ismemcached','1'); + } + + $VERSION = '3.00.00.036'; } use DBI; @@ -229,9 +246,39 @@ 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 } +=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 # @@ -275,6 +322,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. +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>. @@ -309,10 +360,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"}); @@ -514,7 +575,7 @@ the sysprefs cache. sub set_preference { my $self = shift; - my $var = shift; + my $var = lc(shift); my $value = shift; my $dbh = C4::Context->dbh or return 0; @@ -530,7 +591,9 @@ sub set_preference { ON DUPLICATE KEY UPDATE value = VALUES(value) " ); - $sth->execute( $var, $value ); + if($sth->execute( $var, $value )) { + $sysprefs{$var} = $value; + } $sth->finish; }