1 package Koha::Template::Plugin::Cache;
3 # Copyright Catalyst IT 2011
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use base qw( Template::Plugin );
26 #------------------------------------------------------------------------
28 #------------------------------------------------------------------------
31 my ( $class, $context, $params ) = @_;
33 if ( $params->{cache} ) {
34 $cache = delete $params->{cache};
38 $cache = Koha::Caches->get_instance();
48 #------------------------------------------------------------------------
50 # template => 'foo.html',
51 # keys => {'user.name', user.name},
54 #------------------------------------------------------------------------
57 my ( $self, $params ) = @_;
58 $self->_cached_action( 'include', $params );
62 my ( $self, $params ) = @_;
63 $self->_cached_action( 'process', $params );
67 my ( $self, $action, $params ) = @_;
69 if ( $params->{key} ) {
70 $key = delete $params->{key};
73 my $cache_keys = $params->{keys};
78 map { "$_=$cache_keys->{$_}" } keys %{$cache_keys}
82 my $result = $self->{CACHE}->get_from_cache($key);
84 $result = $self->{CONTEXT}->$action( $params->{template} );
86 ->set_in_cache( $key, $result, { expiry => $params->{ttl} } );
95 Koha::Template::Plugin::Cache - cache output of templates
99 [% USE cache = Cache %]
103 'template' => 'slow.html',
104 'keys' => {'user.name' => user.name},
108 # or with a pre-defined Cache::* object and key
110 [% USE cache = Cache( cache => mycache ) %]
113 'template' => 'slow.html',