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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 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.
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',