LP#1449709: caching compiled Template Toolkit templates user/gmcharlt/lp1449709_cache_compiled_templates
authorGalen Charlton <gmc@esilibrary.com>
Tue, 28 Apr 2015 19:06:48 +0000 (19:06 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 30 Apr 2015 18:09:17 +0000 (18:09 +0000)
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 <gmc@esilibrary.com>
Open-ILS/examples/apache/eg_vhost.conf.in
Open-ILS/examples/apache_24/eg_vhost.conf.in
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm

index 87e9054..d26151e 100644 (file)
@@ -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
index 3d60fda..9562725 100644 (file)
@@ -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
index 682e2d6..7f37c0d 100644 (file)
@@ -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);