[Templates] Enabling caching of templates under mod_perl?

Andrew Light andrewlight7@googlemail.com
Thu, 19 Jul 2007 22:52:54 +0200


------=_Part_110776_19804650.1184878374685
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Randal,

thanks a lot for your fast and really helpful answer.
CACHE_SIZE is not defined within my config, so it should be set to undef.
I have set the COMPILE DIR and have the compiled templates already written
to disk on the web server.

The one thing I have to figure out now, is how to manage the global varialb=
e
thing. To be honest, I have never heard about the Apache::Registry hack, I
just pop in all of my regular CGI files in a mod_perl environment and don=
=B4t
really have any special codes for mod_perl execution. Are there any
resources on this, that I should study?

I tried the thing with the lexically scoped "our" varialbe snippet
equivalent to your suggestion, but it seems like the template object is
still created on each hit (it appears from the performance I am encounterin=
g
- I discover no speed up whatsoever and trace statements put into the
constructor also give me the same information, that the template object is
still created on each call) and the compiled templates are written to disk
freshly on each new creation. Unfortunately the compiled templates alwways
get the same dates whenever written to disk, so i can=B4t finally say wheth=
er
they are really newly created on each hit.
Is there any way to set the date on those compiled template files to their
creation date on disk? This would help me in my debugging encounters.

Thanks for your time.



2007/7/16, Randal L. Schwartz <merlyn@stonehenge.com>:
>
> >>>>> "Andrew" =3D=3D Andrew Light <andrewlight7@googlemail.com> writes:
>
> Andrew> I am currently running my web-app under mod_perl, but as far as I
> can
> Andrew> see, none of the dynamic pages, put together using the TT is bein=
g
> Andrew> chached.
>
> a) Don't create the Template object on each hit.
> b) Be sure CACHE_SIZE is undef, or set to a high value.
> c) Set COMPILE_DIR to some place that the web process can write.
>
> Step "a" is easy to get wrong, if you're converting CGI code to simply
> using the Apache::Registry hack.  Be sure you have something like:
>
>       our $engine ||=3D Template->new(...);
>
> rather than:
>
>       my $engine =3D Template->new(...);
>
> which is how it would typically be written in CGI.
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
> 0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
> training!
>

------=_Part_110776_19804650.1184878374685
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Randal,<br><br>thanks a lot for your fast and really helpful answer.<br>CAC=
HE_SIZE is not defined within my config, so it should be set to undef.<br>I=
 have set the COMPILE DIR and have the compiled templates already written t=
o disk on the web server.
<br><br>The one thing I have to figure out now, is how to manage the global=
 varialbe thing. To be honest, I have never heard about the Apache::Registr=
y hack, I just pop in all of my regular CGI files in a mod_perl environment=
 and don=B4t really have any special codes for mod_perl execution. Are ther=
e any resources on this, that I should study?
<br><br>I tried the thing with the lexically scoped &quot;our&quot; varialb=
e snippet equivalent to your suggestion, but it seems like the template obj=
ect is still created on each hit (it appears from the performance I am enco=
untering - I discover no speed up whatsoever and trace statements put into =
the constructor also give me the same information, that the template object=
 is still created on each call) and the compiled templates are written to d=
isk freshly on each new creation. Unfortunately the compiled templates alww=
ays get the same dates whenever written to disk, so i can=B4t finally say w=
hether they are really newly created on each hit.
<br>Is there any way to set the date on those compiled template files to th=
eir creation date on disk? This would help me in my debugging encounters.<b=
r><br>Thanks for your time.<br><br><br><br><div><span class=3D"gmail_quote"=
>
2007/7/16, Randal L. Schwartz &lt;<a href=3D"mailto:merlyn@stonehenge.com">=
merlyn@stonehenge.com</a>&gt;:</span><blockquote class=3D"gmail_quote" styl=
e=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; =
padding-left: 1ex;">
&gt;&gt;&gt;&gt;&gt; &quot;Andrew&quot; =3D=3D Andrew Light &lt;<a href=3D"=
mailto:andrewlight7@googlemail.com">andrewlight7@googlemail.com</a>&gt; wri=
tes:<br><br>Andrew&gt; I am currently running my web-app under mod_perl, bu=
t as far as I can
<br>Andrew&gt; see, none of the dynamic pages, put together using the TT is=
 being<br>Andrew&gt; chached.<br><br>a) Don&#39;t create the Template objec=
t on each hit.<br>b) Be sure CACHE_SIZE is undef, or set to a high value.
<br>c) Set COMPILE_DIR to some place that the web process can write.<br><br=
>Step &quot;a&quot; is easy to get wrong, if you&#39;re converting CGI code=
 to simply<br>using the Apache::Registry hack.&nbsp;&nbsp;Be sure you have =
something like:
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;our $engine ||=3D Template-&gt;=
new(...);<br><br>rather than:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my=
 $engine =3D Template-&gt;new(...);<br><br>which is how it would typically =
be written in CGI.<br><br>--<br>Randal L. Schwartz - Stonehenge Consulting =
Services, Inc. - +1 503 777 0095
<br>&lt;<a href=3D"mailto:merlyn@stonehenge.com">merlyn@stonehenge.com</a>&=
gt; &lt;URL:<a href=3D"http://www.stonehenge.com/merlyn/">http://www.stoneh=
enge.com/merlyn/</a>&gt;<br>Perl/Unix/security consulting, Technical writin=
g, Comedy, etc. etc.
<br>See <a href=3D"http://PerlTraining.Stonehenge.com">PerlTraining.Stonehe=
nge.com</a> for onsite and open-enrollment Perl training!<br></blockquote><=
/div><br>

------=_Part_110776_19804650.1184878374685--