Catalyst::Wiki
/meta/tracpagestoport/increasettperformance

Increase your Template Toolkit Performance

You can increase the performance of your templates by using a template cache for pre-compiled templates and the XS version of the TT stash. Simply use the following code in your view. If you don't have the XS Stash module, you can rebuild Template Toolkit and choose to build it when it asks you.

Warning: Do not use the XS Stash if you need to access tied hashes in your templates.

 package MyApp::V::TT;

 use strict;
 use base 'Catalyst::View::TT';
 use Template::Stash::XS;

 __PACKAGE__->config(
    COMPILE_DIR => "/tmp/template_cache",
    STASH => Template::Stash::XS->new,
 );

 1;

Note: You might want to specify COMPILE_DIR as "/tmp/template_cache_$<", which adds the user id to the directory name if your application may be run as different users (i.e. from Apache and from developer login accounts). Template Toolkit creates cache files with permissions 0600, so if a common cache directory is used, a cache file generated by developer while debugging could prevent a production application running as the web user from rendering a template!

See also:

Doesn't TT use these Options by default?

If you selected "use XS Stash by default for all templates" when you installed TT, it will use the XS Stash. File caching is not enabled unless you specify a COMPILE_DIR yourself.