Bug 4305 Get Amazon book covers for ISBN13
[koha.git] / C4 / Cache.pm
blobebe881a18176e1ad4bdfe50cd3b1a5ac44c0b4cc
1 package C4::Cache;
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
10 # version.
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.
20 =head1 NAME
22 C4::Cache - Handling caching of html and Objects for Koha
24 =head1 SYNOPSIS
26 use C4::Cache (cache_type => $cache_type, %params );
28 =head1 DESCRIPTION
30 Base class for C4::Cache::X. Subclasses need to provide the following methods
32 B<_cache_handle ($params_hr)> - cache handle creator
34 B<set_in_cache ($key, $value, $expiry)>
36 B<get_from_cache ($key)>
38 B<clear_from_cache ($key)>
40 B<flush_all ()>
42 =head1 FUNCTIONS
44 =cut
46 use strict;
47 use warnings;
48 use Carp;
50 use base qw(Class::Accessor);
52 use C4::Cache::Memcached;
53 use C4::Cache::FastMemcached;
55 __PACKAGE__->mk_ro_accessors( qw( cache ) );
57 sub new {
58 my $class = shift;
59 my %param = @_;
61 my $cache_type = $param{cache_type} || 'memcached';
62 my $subclass = __PACKAGE__."::".ucfirst($cache_type);
63 my $cache = $subclass->_cache_handle(\%param)
64 or croak "Cannot create cache handle for '$cache_type'";
65 return bless $class->SUPER::new({cache => $cache}), $subclass;
68 =head2 EXPORT
70 None by default.
72 =head1 SEE ALSO
74 C4::Cache::Memcached
76 =head1 AUTHOR
78 Chris Cormack, E<lt>chris@bigballofwax.co.nzE<gt>
80 =cut
84 __END__