croak "No key" unless $key;
$ENV{DEBUG} && warn "set_in_cache for $key";
+ return unless $self->{cache};
return unless $self->{have_chi};
if ( defined $expiry ) {
my ( $self, $key ) = @_;
croak "No key" unless $key;
$ENV{DEBUG} && warn "get_from_cache for $key";
+ return unless $self->{cache};
return unless $self->{have_chi};
return $self->{cache}->get($key);
}
sub clear_from_cache {
my ( $self, $key ) = @_;
croak "No key" unless $key;
+ return unless $self->{cache};
return unless $self->{have_chi};
return $self->{cache}->remove($key);
}
sub flush_all {
my $self = shift;
+ return unless $self->{cache};
return unless $self->{have_chi};
return $self->{cache}->clear();
}
use strict;
use warnings;
use Carp;
-use CHI;
+use Module::Load::Conditional qw(can_load);
use base qw(Koha::Cache);
sub _cache_handle {
my $class = shift;
my $params = shift;
- return CHI->new(
- driver => 'FastMmap',
- namespace => $params->{'namespace'} || 'koha',
- expire_in => 600,
- cache_size => $params->{'cachesize'} || '1m',
- );
+ if ( can_load( modules => { CHI => undef } ) ) {
+ return CHI->new(
+ driver => 'FastMmap',
+ namespace => $params->{'namespace'} || 'koha',
+ expire_in => 600,
+ cache_size => $params->{'cachesize'} || '1m',
+ );
+ } else {
+ return undef;
+ }
}
1;
use strict;
use warnings;
use Carp;
-use CHI;
+use Module::Load::Conditional qw(can_load);
use base qw(Koha::Cache);
sub _cache_handle {
my $class = shift;
my $params = shift;
- return CHI->new(
- driver => 'Memory',
- namespace => $params->{'namespace'} || 'koha',
- expire_in => 600,
- max_size => $params->{'max_size'} || 8192 * 1024,
- global => 1,
- );
+ if ( can_load( modules => { CHI => undef } ) ) {
+ return CHI->new(
+ driver => 'Memory',
+ namespace => $params->{'namespace'} || 'koha',
+ expire_in => 600,
+ max_size => $params->{'max_size'} || 8192 * 1024,
+ global => 1,
+ );
+ } else {
+ return undef;
+ }
}
1;