From: Galen Charlton Date: Tue, 28 Apr 2015 19:06:48 +0000 (+0000) Subject: LP#1449709: caching compiled Template Toolkit templates X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fgmcharlt%2Flp1449709_cache_compiled_templates;p=working%2FEvergreen.git 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 anticipates future work to also cache TT objects, so at the moment, setting OILSWebTemplateStatTTL has little effect. 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. Signed-off-by: Galen Charlton --- 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 3d60fda7a5..9562725ac8 100644 --- a/Open-ILS/examples/apache_24/eg_vhost.conf.in +++ b/Open-ILS/examples/apache_24/eg_vhost.conf.in @@ -652,7 +652,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 682e2d6559..7f37c0d656 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm @@ -60,6 +60,16 @@ sub handler_guts { 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' @@ -160,7 +170,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);