sub new {
my $class = shift;
my $param = shift;
- my $cache_type = $param->{cache_type} || 'memcached';
+ my $cache_type = $ENV{CACHING_SYSTEM} || $param->{cache_type} || 'memcached';
my $subclass = __PACKAGE__."::".ucfirst($cache_type);
my $cache = $subclass->_cache_handle($param)
or croak "Cannot create cache handle for '$cache_type'";
return bless $class->SUPER::new({cache => $cache}), $subclass;
}
+sub is_cache_active {
+ return $ENV{CACHING_SYSTEM} ? '1' : '' ;
+}
+
=head2 EXPORT
None by default.
=head1 AUTHOR
Chris Cormack, E<lt>chris@bigballofwax.co.nzE<gt>
+Paul Poulain, E<lt>paul.poulain@biblibre.comE<gt>
=cut
sub _cache_handle {
my $class = shift;
my $params = shift;
- my @servers = split /,/, $params->{'cache_servers'};
+ my @servers = split /,/, $params->{'cache_servers'}?$params->{'cache_servers'}:$ENV{MEMCACHED_SERVERS};
+ $ENV{DEBUG} && warn "Caching server settings: ".join(', ',@servers)." with ".($ENV{MEMCACHED_NAMESPACE} || $params->{'namespace'} || 'koha');
return Cache::Memcached->new(
servers => \@servers,
- namespace => $params->{'namespace'} || 'KOHA',
+ debug => 0,
+ compress_threshold => 10_000,
+ expire_time => 600,
+ namespace => $ENV{MEMCACHED_NAMESPACE} || $params->{'namespace'} || 'koha',
);
}
my ( $self, $key, $value, $expiry ) = @_;
croak "No key" unless $key;
$self->cache->set_debug;
+ $ENV{DEBUG} && warn "set_in_cache for Memcache $key";
if ( defined $expiry ) {
return $self->cache->set( $key, $value, $expiry );
sub get_from_cache {
my ( $self, $key ) = @_;
croak "No key" unless $key;
+ $ENV{DEBUG} && warn "get_from_cache for Memcache $key";
return $self->cache->get($key);
}
use JSON;
use CGI;
+use Koha::Cache;
+
my $query = CGI->new();
my $report = $query->param('id');
my $cache;
-my $usecache = C4::Context->ismemcached;
my ( $sql, $type, $name, $notes, $cache_expiry, $public ) =
get_saved_report($report);
die "Sorry this report is not public\n" unless $public;
-if ($usecache) {
- require Koha::Cache;
- Koha::Cache->import();
+if (Koha::Cache->is_cache_active) {
$cache = Koha::Cache->new(
- {
- 'cache_type' => 'memcached',
- 'cache_servers' => $ENV{'MEMCACHED_SERVERS'}
- }
);
- my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha';
- my $page = $cache->get_from_cache("$namespace:opac:report:$report");
+ my $page = $cache->get_from_cache("opac:report:$report");
if ($page) {
print $query->header;
print $page;
my $json_text = to_json($lines);
print $json_text;
-if ($usecache) {
- my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha';
- $cache->set_in_cache( "$namespace:opac:report:$report",
- $json_text, $cache_expiry );
+if (Koha::Cache->is_cache_active) {
+ $cache->set_in_cache( "opac:report:$report", $json_text, $cache_expiry );
}
use JSON;
use CGI;
+use Koha::Cache;
+
+
my $query = CGI->new();
my $report = $query->param('id');
my $cache;
-my $usecache = C4::Context->ismemcached;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
}
);
-if ($usecache) {
- require Koha::Cache;
- Koha::Cache->import();
- $cache = Koha::Cache->new(
- {
- 'cache_type' => 'memcached',
- 'cache_servers' => $ENV{'MEMCACHED_SERVERS'}
- }
- );
- my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha';
- my $page = $cache->get_from_cache("$namespace:intranet:report:$report");
+if (Koha::Cache->is_cache_active) {
+ $cache = Koha::Cache->new();
+ my $page = $cache->get_from_cache("intranet:report:$report");
if ($page) {
print $query->header;
print $page;
my $json_text = to_json($lines);
print $json_text;
-if ($usecache) {
- my $namespace = $ENV{'MEMCACHED_NAMESPACE'} || 'koha';
- $cache->set_in_cache( "$namespace:intranet:report:$report",
- $json_text, $cache_expiry );
+if (Koha::Cache->is_cache_active) {
+ $cache->set_in_cache( "intranet:report:$report", $json_text, $cache_expiry );
}