1 package Koha::Cache::FastMemcached;
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.
24 use Cache::Memcached::Fast;
25 use IO::Compress::Gzip;
26 use IO::Uncompress::Gunzip;
29 use base qw(C4::Cache);
35 my @servers = split /,/, $params->{'cache_servers'};
37 return Cache::Memcached::Fast->new(
40 namespace => $params->{'namespace'} || 'KOHA',
41 connect_timeout => $params->{'connect_timeout'} || 2,
42 io_timeout => $params->{'io_timeout'} || 2,
44 compress_threshold => 100_000,
45 compress_ratio => 0.9,
47 [ \&IO::Compress::Gzip::gzip, \&IO::Uncompress::Gunzip::gunzip ],
53 serialize_methods => [ \&Storable::freeze, \&Storable::thaw ],
60 my ( $self, $key, $value, $expiry ) = @_;
61 croak "No key" unless $key;
63 if ( defined $expiry ) {
64 return $self->cache->set( $key, $value, $expiry );
67 return $self->cache->set( $key, $value );
72 my ( $self, $key ) = @_;
73 croak "No key" unless $key;
74 return $self->cache->get($key);
77 sub clear_from_cache {
78 my ( $self, $key ) = @_;
79 croak "No key" unless $key;
80 return $self->cache->delete($key);
85 return $self->cache->flush_all;
93 C4::Cache::FastMemcached - memcached::fast subclass of C4::Cache