Bugzilla – Attachment 15502 Details for
Bug 7387
Add Template::Toolkit plugin to allow caching of includes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 7387 : Adding a caching plugin for Template::Toolkit
SIGNED-OFF-Bug-7387--Adding-a-caching-plugin-for-T.patch (text/plain), 4.36 KB, created by
Bernardo Gonzalez Kriegel
on 2013-02-19 01:37:07 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 7387 : Adding a caching plugin for Template::Toolkit
Filename:
MIME Type:
Creator:
Bernardo Gonzalez Kriegel
Created:
2013-02-19 01:37:07 UTC
Size:
4.36 KB
patch
obsolete
>From 7814d5526f819329e28900f54c87909ae17cd96e Mon Sep 17 00:00:00 2001 >From: Chris Cormack <chrisc@catalyst.net.nz> >Date: Fri, 30 Dec 2011 09:25:29 +1300 >Subject: [PATCH] [SIGNED-OFF] Bug 7387 : Adding a caching plugin for > Template::Toolkit > >To use this you need to do something like > >-[% INCLUDE 'doc-head-open.inc' %] >+[% USE cache = Cache %] >+[% cache.inc( >+ 'template' => 'doc-head-open.inc', >+ 'keys' => {'dochead' => 'dochead'}, >+ 'ttl' => 360 >+ ) >+%] > >Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com> >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> > >Comment: Works. Tested modifying as described opac-main.tt >Follow up to fix tabulations. >--- > Koha/Template/Plugin/Cache.pm | 120 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 120 insertions(+) > create mode 100644 Koha/Template/Plugin/Cache.pm > >diff --git a/Koha/Template/Plugin/Cache.pm b/Koha/Template/Plugin/Cache.pm >new file mode 100644 >index 0000000..1bdb665 >--- /dev/null >+++ b/Koha/Template/Plugin/Cache.pm >@@ -0,0 +1,120 @@ >+package Koha::Template::Plugin::Cache; >+ >+# Copyright Catalyst IT 2011 >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use strict; >+use warnings; >+use vars qw( $VERSION ); >+use base qw( Template::Plugin ); >+use Template::Plugin; >+use C4::Context; >+$VERSION = '0.01'; >+ >+#------------------------------------------------------------------------ >+# new(\%options) >+#------------------------------------------------------------------------ >+ >+sub new { >+ my ( $class, $context, $params ) = @_; >+ my $cache; >+ if ( $params->{cache} ) { >+ $cache = delete $params->{cache}; >+ } >+ else { >+ require Koha::Cache; >+ $cache = Koha::Cache->new( { 'cache_type' => 'memcached', 'cache_servers' => C4::Context->config('memcached_servers') }); >+ } >+ my $self = bless { >+ CACHE => $cache, >+ CONFIG => $params, >+ CONTEXT => $context, >+ }, $class; >+ return $self; >+} >+ >+#------------------------------------------------------------------------ >+# $cache->include({ >+# template => 'foo.html', >+# keys => {'user.name', user.name}, >+# ttl => 60, #seconds >+# }); >+#------------------------------------------------------------------------ >+ >+sub inc { >+ my ( $self, $params ) = @_; >+ $self->_cached_action( 'include', $params ); >+} >+ >+sub proc { >+ my ( $self, $params ) = @_; >+ $self->_cached_action( 'process', $params ); >+} >+ >+sub _cached_action { >+ my ( $self, $action, $params ) = @_; >+ my $key; >+ if ( $params->{key} ) { >+ $key = delete $params->{key}; >+ } >+ else { >+ my $cache_keys = $params->{keys}; >+ $key = join( >+ ':', >+ ( >+ $params->{template}, >+ map { "$_=$cache_keys->{$_}" } keys %{$cache_keys} >+ ) >+ ); >+ } >+ my $result = $self->{CACHE}->get_from_cache($key); >+ if ( !$result ) { >+ warn "here in not in cache"; >+ $result = $self->{CONTEXT}->$action( $params->{template} ); >+ $self->{CACHE}->set_in_cache( $key, $result, $params->{ttl} ); >+ } >+ return $result; >+} >+ >+1; >+ >+=head1 NAME >+ >+Koha::Template::Plugin::Cache - cache output of templates >+ >+=head1 SYNOPSIS >+ >+ [% USE cache = Cache %] >+ >+ >+ [% cache.inc( >+ 'template' => 'slow.html', >+ 'keys' => {'user.name' => user.name}, >+ 'ttl' => 360 >+ ) %] >+ >+ # or with a pre-defined Cache::* object and key >+ >+ [% USE cache = Cache( cache => mycache ) %] >+ >+ [% cache.inc( >+ 'template' => 'slow.html', >+ 'key' => mykey, >+ 'ttl' => 360 >+ ) %] >+ >+__END__ >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7387
:
6959
|
7368
|
14358
|
15502
|
15503
|
15892
|
15893