Browse Source

Bug 11921: Restore memcached infos to koha-conf

MEMCACHED_SERVERS and MEMCACHED_NAMESPACE should be moved back to
koha-conf instead of an ENV var to let command line scripts use
the cache mechanism.

TODO:
- Add the entries to koha-conf.xml
- Remove occurrences of MEMCACHED_SERVERS in package, apache and plack files

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
16.11.x
Jonathan Druart 6 years ago
committed by Kyle M Hall
parent
commit
4fc3750f9a
  1. 77
      C4/Context.pm
  2. 9
      Koha/Cache.pm

77
C4/Context.pm

@ -18,7 +18,7 @@ package C4::Context;
use strict;
use warnings;
use vars qw($AUTOLOAD $context @context_stack $servers $memcached $ismemcached);
use vars qw($AUTOLOAD $context @context_stack $servers);
BEGIN {
if ($ENV{'HTTP_USER_AGENT'}) {
require CGI::Carp;
@ -86,23 +86,6 @@ BEGIN {
$CGI::LIST_CONTEXT_WARN = 0;
}
} # else there is no browser to send fatals to!
# 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');
}
}
use Encode;
@ -242,38 +225,9 @@ 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;
}
}
=head2 db_scheme2dbi
my $dbd_driver_name = C4::Context::db_schema2dbi($scheme);
@ -355,22 +309,23 @@ sub new {
return;
}
}
if ($ismemcached) {
# retrieve 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
my $conf_cache = Koha::Caches->get_instance('config');
if ( $conf_cache ) {
$self = $conf_cache->get_from_cache('kohaconf');
}
unless ( %$self ) {
$self = read_config_file($conf_fname);
}
$self->{"config_file"} = $conf_fname;
warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"});
return if !defined($self->{"config"});
if ( $conf_cache ) {
# FIXME it may be better to use the memcached servers from the config file
# to cache it
$conf_cache->set_in_cache('koha_conf', $self)
}
unless ( exists $self->{config} or defined $self->{config} ) {
warn "read_config_file($conf_fname) returned undef";
return;
}
$self->{"Zconn"} = undef; # Zebra Connections
$self->{"userenv"} = undef; # User env

9
Koha/Cache.pm

@ -78,7 +78,7 @@ sub new {
$ENV{DEBUG} && carp "Default caching system: $self->{'default_type'}";
$self->{'timeout'} ||= 0;
$self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE} || 'koha';
$self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') || 'koha';
$self->{namespace} .= ":$subnamespace:";
if ( $self->{'default_type'} eq 'memcached'
@ -116,11 +116,8 @@ sub new {
sub _initialize_memcached {
my ($self) = @_;
my @servers =
split /,/, $self->{'cache_servers'}
? $self->{'cache_servers'}
: ($ENV{MEMCACHED_SERVERS} || '');
return if !@servers;
my @servers = split /,/, $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers') || '';
return unless @servers;
$ENV{DEBUG}
&& carp "Memcached server settings: "

Loading…
Cancel
Save