use strict;
use warnings;
-use vars qw($VERSION $AUTOLOAD $context @context_stack);
-
-use Koha::Cache;
+use vars qw($VERSION $AUTOLOAD $context @context_stack $servers $memcached $ismemcached);
BEGIN {
if ($ENV{'HTTP_USER_AGENT'}) {
}
} # 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');
+ }
+
$VERSION = '3.07.00.049';
}
sub read_config_file { # Pass argument naming config file to read
my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => '');
- if (Koha::Cache->is_cache_active()) {
- my $cache = Koha::Cache->new();
- $cache->set_in_cache('kohaconf', $koha) if defined $cache;
+ 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
#
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 cache (if configured) and uses
-those values until them expire and re-reads them.
+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>.
}
}
- if (Koha::Cache->is_cache_active()) {
- # retrieve from cache
- my $cache = Koha::Cache->new();
- $self = $cache->get_from_cache('kohaconf') if defined $cache;
- $self = { };
- }
- if (!keys %$self) {
- # not cached yet
+ 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);
}
sub preference {
my $self = shift;
my $var = lc(shift); # The system preference to return
- my $cache;
if (exists $sysprefs{$var}) {
return $sysprefs{$var};
}
- if (Koha::Cache->is_cache_active()) {
- $cache = Koha::Cache->new();
- if (defined $cache) {
- $sysprefs{$var} = $cache->get_from_cache("syspref:$var");
- return $sysprefs{$var} if (defined $sysprefs{$var});
- }
- }
-
my $dbh = C4::Context->dbh or return 0;
# Look up systempreferences.variable==$var
LIMIT 1
END_SQL
$sysprefs{$var} = $dbh->selectrow_array( $sql, {}, $var );
- if (Koha::Cache->is_cache_active() && defined $cache) {
- $cache->set_in_cache("syspref:$var");
- }
return $sysprefs{$var};
}
sub clear_syspref_cache {
%sysprefs = ();
- if (Koha::Cache->is_cache_active()) {
- my $cache = Koha::Cache->new();
- $cache->flush_all() if defined $cache; # Sorry, this is unpleasant
- }
}
=head2 set_preference
" );
if($sth->execute( $var, $value )) {
- if (Koha::Cache->is_cache_active()) {
- my $cache = Koha::Cache->new();
- $cache->set_in_cache("syspref:$var", $value) if defined $cache;
- }
$sysprefs{$var} = $value;
}
$sth->finish;