Merge remote-tracking branch 'origin/new/bug_6858'
[koha.git] / Koha / Cache.pm
1 package Koha::Cache;
2
3 # Copyright 2009 Chris Cormack and The Koha Dev Team
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
15 #
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.
19
20 =head1 NAME
21
22 Koha::Cache - Handling caching of html and Objects for Koha
23
24 =head1 SYNOPSIS
25
26   use Koha::Cache (cache_type => $cache_type, %params );
27
28 =head1 DESCRIPTION
29
30 Base class for Koha::Cache::X. Subclasses need to provide the following methods
31
32 B<_cache_handle ($params_hr)> - cache handle creator
33
34 B<set_in_cache ($key, $value, $expiry)>
35
36 B<get_from_cache ($key)>
37
38 B<clear_from_cache ($key)>
39
40 B<flush_all ()>
41
42 =head1 FUNCTIONS
43
44 =cut
45
46 use strict;
47 use warnings;
48 use Carp;
49
50 use base qw(Class::Accessor);
51
52 use Koha::Cache::Memcached;
53
54 __PACKAGE__->mk_ro_accessors( qw( cache ) );
55
56 sub new {
57     my $class = shift;
58     my $param = shift;
59     my $cache_type = $ENV{CACHING_SYSTEM} || $param->{cache_type} || 'memcached';
60     my $subclass = __PACKAGE__."::".ucfirst($cache_type);
61     my $cache    = $subclass->_cache_handle($param)
62       or croak "Cannot create cache handle for '$cache_type'";
63     return bless $class->SUPER::new({cache => $cache}), $subclass;
64 }
65
66 sub is_cache_active {
67     return $ENV{CACHING_SYSTEM} ? '1' : '' ;
68 }
69
70 =head2 EXPORT
71
72 None by default.
73
74 =head1 SEE ALSO
75
76 Koha::Cache::Memcached
77
78 =head1 AUTHOR
79
80 Chris Cormack, E<lt>chris@bigballofwax.co.nzE<gt>
81 Paul Poulain, E<lt>paul.poulain@biblibre.comE<gt>
82
83 =cut
84
85 1;
86
87 __END__