Bug 8092: Cheer up Jenkins on loading Cache modules
authorJared Camins-Esakov <jcamins@cpbibliography.com>
Sat, 9 Jun 2012 14:57:52 +0000 (10:57 -0400)
committerPaul Poulain <paul.poulain@biblibre.com>
Mon, 11 Jun 2012 14:55:43 +0000 (16:55 +0200)
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
Koha/Cache.pm
Koha/Cache/Fastmmap.pm
Koha/Cache/Memory.pm

index 636d73e..740a133 100644 (file)
@@ -92,6 +92,7 @@ sub set_in_cache {
     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 ) {
@@ -106,6 +107,7 @@ sub get_from_cache {
     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);
 }
@@ -113,12 +115,14 @@ sub get_from_cache {
 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();
 }
index 10c4eb0..bad19f5 100644 (file)
@@ -20,19 +20,23 @@ package Koha::Cache::Fastmmap;
 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;
index daeeb4a..da09765 100644 (file)
@@ -20,20 +20,24 @@ package Koha::Cache::Memory;
 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;