in reply to Re^2: Best practices: Generating HTML content
in thread Best practices: Generating HTML content
Hi Dallaylaen,
TT does not cache compiled templates. This can be overcome but not easily.
Just to clarify, I assume you mean that the Template Toolkit does not cache compiled templates *persistently* if they originated as a reference to a string, as you showed.
See the documentation on "Caching and Compiling Options".
You can cache compiled templates in memory explicitly without even processing them using template():
And of course you can cache persistently between program runs if you use the right configuration options (and use a template file or filehandle):$ perl -MTemplate -wE ' my $tt = Template->new; my $compiled = $tt->template(\"In-place [% foo %] query\n"); my $answer = 40; $tt->process( $compiled, {foo => $answer++} ) for 0..2; ' In-place 40 query In-place 41 query In-place 42 query
I'm sure you knew this, just clarifying for future readers...my $tt = Template->new( INCLUDE_PATH => '/some/path', COMPILE_DIR => '/other/path', COMPILE_EXT => '.compiled', ); my $file = 'foo.tt'; my $data = { foo => 42 }; $tt->process( $file, $data ) or die $tt->error; # Template will be compiled and cached at '/other/path/foo.tt.compiled +' # and that file will be used until '/some/path/foo.tt' changes
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Best practices: Generating HTML content
by Dallaylaen (Chaplain) on Dec 24, 2017 at 18:03 UTC |