From a42f4e9f3d45a5dbc5eefcd86f0d0ee0ad001660 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 28 Apr 2015 19:06:48 +0000 Subject: [PATCH] LP#1449709: caching compiled Template Toolkit templates This patch enables caching of compiled Template Toolkit files on Evergreen web servers, which can provide a modest improvement in the time it takes (say) TPAC to render a page, particularly by a fresh Apache backend. This is controlled by a new Apache virtualhost variable, OILSWebCompiledTemplateCache, which can be set to a directory on the webserver for storing compiled templates. This is enabled by default for new installations. This patch also adds OILSWebTemplateStatTTL, which can be use to tweak the STAT_TTL Template Toolkit setting. Note this bit works because of the caching of TT handlers added by the previous patch. Finally, this patch also fixes a bug where attempting to disable OILSWebDebugTemplate would result in internal server errors; it also sets the default value of this setting to false. Note: the caching added by this patch and the previous one mean that if a change to (say) TPAC templates is made on the file system, it is now required to reload Apache to have a guarantee that the change is visible, although one can also wait the OILSWebTemplateStatTTL interval. Signed-off-by: Galen Charlton Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton Signed-off-by: Bill Erickson --- Open-ILS/examples/apache/eg_vhost.conf.in | 7 ++++++- Open-ILS/examples/apache_24/eg_vhost.conf.in | 7 ++++++- Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm | 13 +++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Open-ILS/examples/apache/eg_vhost.conf.in b/Open-ILS/examples/apache/eg_vhost.conf.in index 87e90543dc..d26151ec04 100644 --- a/Open-ILS/examples/apache/eg_vhost.conf.in +++ b/Open-ILS/examples/apache/eg_vhost.conf.in @@ -646,7 +646,12 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT] PerlSetVar OILSWebDefaultTemplateExtension "tt2" # Enable Template-Toolkit error debugging messages (apache error log) - PerlSetVar OILSWebDebugTemplate "true" + PerlSetVar OILSWebDebugTemplate "false" + # local cache of compiled Template Toolkit templates + PerlSetVar OILSWebCompiledTemplateCache "/tmp/eg_template_cache" + # template TTL - how long, in seconds, that Template Toolkit + # waits to check for updated template files + #PerlSetVar OILSWebTemplateStatTTL 60 # ------------------------------------------------------- # Media Prefix. In the 3rd example, the protocol (http) is enforced diff --git a/Open-ILS/examples/apache_24/eg_vhost.conf.in b/Open-ILS/examples/apache_24/eg_vhost.conf.in index d4bbd785cd..f73361632d 100644 --- a/Open-ILS/examples/apache_24/eg_vhost.conf.in +++ b/Open-ILS/examples/apache_24/eg_vhost.conf.in @@ -644,7 +644,12 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT] PerlSetVar OILSWebDefaultTemplateExtension "tt2" # Enable Template-Toolkit error debugging messages (apache error log) - PerlSetVar OILSWebDebugTemplate "true" + PerlSetVar OILSWebDebugTemplate "false" + # local cache of compiled Template Toolkit templates + PerlSetVar OILSWebCompiledTemplateCache "/tmp/eg_template_cache" + # template TTL - how long, in seconds, that Template Toolkit + # waits to check for updated template files + #PerlSetVar OILSWebTemplateStatTTL 60 # ------------------------------------------------------- # Media Prefix. In the 3rd example, the protocol (http) is enforced diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm index db0645ddbc..8b3fcbfb73 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm @@ -66,13 +66,22 @@ sub handler_guts { $processor_key .= $r->dir_config('OILSWebContextLoader').':'; # ... and context loader $processor_key .= $ctx->{locale}; # ... and locale # NOTE: context loader and vhost together imply template path and debug template values - # TODO: maybe add STAT_TTL and cache dir from LP#1449709? my $tt = $vhost_processor_cache{$processor_key} || Template->new({ ENCODING => 'utf-8', OUTPUT => ($as_xml) ? sub { parse_as_xml($r, $ctx, @_); } : $r, INCLUDE_PATH => $ctx->{template_paths}, DEBUG => $ctx->{debug_template}, + ( + $r->dir_config('OILSWebCompiledTemplateCache') ? + (COMPILE_DIR => $r->dir_config('OILSWebCompiledTemplateCache')) : + () + ), + ( + ($r->dir_config('OILSWebTemplateStatTTL') =~ /^\d+$/) ? + (STAT_TTL => $r->dir_config('OILSWebTemplateStatTTL')) : + () + ), PLUGINS => { EGI18N => 'OpenILS::WWW::EGWeb::I18NFilter', CGI_utf8 => 'OpenILS::WWW::EGWeb::CGI_utf8' @@ -174,7 +183,7 @@ sub load_context { $ctx->{base_path} = $r->dir_config('OILSWebBasePath'); $ctx->{web_dir} = $r->dir_config('OILSWebWebDir'); - $ctx->{debug_template} = ($r->dir_config('OILSWebDebugTemplate') =~ /true/io); + $ctx->{debug_template} = ($r->dir_config('OILSWebDebugTemplate') =~ /true/io) ? 1 : 0; $ctx->{media_prefix} = $r->dir_config('OILSWebMediaPrefix'); $ctx->{hostname} = $r->hostname; $ctx->{base_url} = $cgi->url(-base => 1); -- 2.43.2