[Templates] TT Speed Question
Paul Makepeace
tt2.org@paulm.com
Wed, 8 Jan 2003 22:17:21 +0000
On Wed, Jan 08, 2003 at 03:15:14PM +0000, Mark Fowler wrote:
> The most important thing with TT performance, the thing that most people
> get wrong, is that you need to have one Template object that persists
> between requests.
>
> This means doing something like:
>
> our $template ||= Template->new();
When I'm handling each page, I have create an INCLUDE_PATH that's
dependent on the URL, so that bits can be dropped into any of the parent
directories.
# @libs is an array of absolute paths searched in order
# for the file specified in the URL. Check from most specific to
# least.
my @libs = map { "$template_root/$_" } (
"",
# etc
);
unshift @libs, map { m~/$~ ? "$_$path" : "$_/$path" } @libs if $path;
# etc
my $template = Template->new({
INCLUDE_PATH => [ @libs ],
# ...
So as it stands it's creating a new Template object per request. Do you
have any suggestions how I might get around this i.e. retain this or
similar behaviour but also make it persist? I didn't 'til now realise
the persistence was that important.
I suppose this boils down to: does the INCLUDE_PATH affect its
internal cache? And can it be set after the creation?
Cheers,
Paul
--
Paul Makepeace ....................................... http://paulm.com/
"What is a telephone? Try weeding instead."
-- http://paulm.com/toys/surrealism/