Greek staff updates
[koha.git] / C4 / Cache.pm
blob6d55b25286a1fb5869c1814afbc4d05b18ad2969
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 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 );
29 =head1 DESCRIPTION
31 Base class for C4::Cache::X. Subclasses need to provide the following methods
33 B<_cache_handle ($params_hr)> - cache handle creator
34 B<set_in_cache ($key, $value, $expiry)>
35 B<get_from_cache ($key)>
36 B<clear_from_cache ($key)>
37 B<flush_all ()>
39 =head1 FUNCTIONS
41 =cut
43 use strict;
44 use warnings;
45 use Carp;
47 use base qw(Class::Accessor);
49 use C4::Cache::Memcached;
50 use C4::Cache::FastMemcached;
52 __PACKAGE__->mk_ro_accessors( qw( cache ) );
54 sub new {
55 my $class = shift;
56 my %param = @_;
58 my $cache_type = $param{cache_type} || 'memcached';
59 my $subclass = __PACKAGE__."::".ucfirst($cache_type);
60 my $cache = $subclass->_cache_handle(\%param)
61 or croak "Cannot create cache handle for '$cache_type'";
62 return bless $class->SUPER::new({cache => $cache}), $subclass;
65 =head2 EXPORT
67 None by default.
69 =head1 SEE ALSO
71 C4::Cache::Memcached
73 =head1 AUTHOR
75 Chris Cormack, E<lt>chris@bigballofwax.co.nzE<gt>
77 =cut
81 __END__