1 package Koha::Cache::Memcached;
3 # Copyright 2009 Chris Cormack and The Koha Dev Team
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 use base qw(Koha::Cache);
31 my @servers = split /,/, $params->{'cache_servers'}?$params->{'cache_servers'}:$ENV{MEMCACHED_SERVERS};
32 $ENV{DEBUG} && warn "Caching server settings: ".join(', ',@servers)." with ".($ENV{MEMCACHED_NAMESPACE} || $params->{'namespace'} || 'koha');
33 return Cache::Memcached->new(
36 compress_threshold => 10_000,
38 namespace => $ENV{MEMCACHED_NAMESPACE} || $params->{'namespace'} || 'koha',
43 my ( $self, $key, $value, $expiry ) = @_;
44 croak "No key" unless $key;
45 $self->cache->set_debug;
46 $ENV{DEBUG} && warn "set_in_cache for Memcache $key";
48 if ( defined $expiry ) {
49 return $self->cache->set( $key, $value, $expiry );
52 return $self->cache->set( $key, $value );
57 my ( $self, $key ) = @_;
58 croak "No key" unless $key;
59 $ENV{DEBUG} && warn "get_from_cache for Memcache $key";
60 return $self->cache->get($key);
63 sub clear_from_cache {
64 my ( $self, $key ) = @_;
65 croak "No key" unless $key;
66 return $self->cache->delete($key);
71 return $self->cache->flush_all;
79 Koha::Cache::Memcached - memcached subclass of Koha::Cache