use Sereal::Encoder;
use Sereal::Decoder;
+use C4::Context;
use Koha::Cache::Object;
use Koha::Config;
use base qw(Class::Accessor);
__PACKAGE__->mk_ro_accessors(
- qw( cache memcached_cache fastmmap_cache memory_cache ));
+ qw( cache memcached_cache ));
our %L1_cache;
our $L1_encoder = Sereal::Encoder->new;
my $subnamespace = $params->{subnamespace} // '';
- $ENV{DEBUG} && carp "Default caching system: $self->{'default_type'}";
-
$self->{'timeout'} ||= 0;
# Should we continue to support MEMCACHED ENV vars?
$self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE};
my @servers = split /,/, $ENV{MEMCACHED_SERVERS} || '';
- unless ( $self->{namespace} and @servers ) {
- my $koha_config = Koha::Config->read_from_file( Koha::Config->guess_koha_conf() );
- $self->{namespace} ||= $koha_config->{config}{memcached_namespace} || 'koha';
- @servers = split /,/, $koha_config->{config}{memcached_servers} // ''
- unless @servers;
- }
+ $self->{namespace} ||= C4::Context->config('memcached_namespace') || 'koha';
+ @servers = split /,/, C4::Context->config('memcached_servers') // ''
+ unless @servers;
$self->{namespace} .= ":$subnamespace:";
if ( $self->{'default_type'} eq 'memcached'
- && can_load( modules => { 'Cache::Memcached::Fast' => undef } )
+ && can_load( modules => { 'Cache::Memcached::Fast::Safe' => undef } )
&& _initialize_memcached($self, @servers)
&& defined( $self->{'memcached_cache'} ) )
{
$self->{'cache'} = $self->{'memcached_cache'};
}
- if ( $self->{'default_type'} eq 'fastmmap'
- && defined( $ENV{GATEWAY_INTERFACE} )
- && can_load( modules => { 'Cache::FastMmap' => undef } )
- && _initialize_fastmmap($self)
- && defined( $self->{'fastmmap_cache'} ) )
- {
- $self->{'cache'} = $self->{'fastmmap_cache'};
- }
-
- $ENV{DEBUG} && carp "Selected caching system: " . ($self->{'cache'} // 'none');
-
return
bless $self,
$class;
return unless @servers;
- $ENV{DEBUG}
- && carp "Memcached server settings: "
- . join( ', ', @servers )
- . " with "
- . $self->{'namespace'};
- # Cache::Memcached::Fast doesn't allow a default expire time to be set
+ # Cache::Memcached::Fast::Safe doesn't allow a default expire time to be set
# so we force it on setting.
- my $memcached = Cache::Memcached::Fast->new(
+ my $memcached = Cache::Memcached::Fast::Safe->new(
{
servers => \@servers,
compress_threshold => 10_000,
return $self;
}
-sub _initialize_fastmmap {
- my ($self) = @_;
- my ($cache, $share_file);
-
- # Temporary workaround to catch fatal errors when: C4::Context module
- # is not loaded beforehand, or Cache::FastMmap init fails for whatever
- # other reason (e.g. due to permission issues - see Bug 13431)
- eval {
- $share_file = join( '-',
- "/tmp/sharefile-koha", $self->{'namespace'},
- C4::Context->config('hostname'), C4::Context->config('database') );
-
- $cache = Cache::FastMmap->new(
- 'share_file' => $share_file,
- 'expire_time' => $self->{'timeout'},
- 'unlink_on_exit' => 0,
- );
- };
- if ( $@ ) {
- warn "FastMmap cache initialization failed: $@";
- return;
- }
- return unless defined $cache;
- $self->{'fastmmap_cache'} = $cache;
- return $self;
-}
-
=head2 is_cache_active
Routine that checks whether or not a default caching method is active on this
my $cache = $options->{cache} || 'cache';
croak "No key" unless $key;
- $ENV{DEBUG} && carp "set_in_cache for $key";
return unless ( $self->{$cache} && ref( $self->{$cache} ) =~ m/^Cache::/ );
my $expiry = $options->{expiry};
my $unsafe = $options->{unsafe} || 0;
$key =~ s/[\x00-\x20]/_/g;
croak "No key" unless $key;
- $ENV{DEBUG} && carp "get_from_cache for $key";
return unless ( $self->{$cache} && ref( $self->{$cache} ) =~ m/^Cache::/ );
# Return L1 cache value if exists