Is the object loaded by the USE directive cached between requests?
Chris Herdt <[email protected]> Mon, 11 May 2015 17:33:23 -0400
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <CAFUsNG+MO+6qVLLhOmUts8NMfdK6gjC4OiavNSr1Br+VpnyZOA@mail.gmail.com> |
--===============4316817633000181923== Content-Type: multipart/alternative; boundary=001a1134b420ab74420515d5203e --001a1134b420ab74420515d5203e Content-Type: text/plain; charset=UTF-8 Does the USE directive load a new instance of the object per request? Or is it cached? I'm trying to speed up a legacy app that uses TT (which is new to me). I discovered the app was making numerous identical database calls to retrieve the authenticated user's info. Each template includes the line [% USE Util; %] at the top -- it's this class where the user info is retrieved. I modified Util.pm so that it checks to see if it already has a user property, checks to make sure the user property contains the same username as the requested user, and if so returns that instead of generating a database call. This drops the load time by 75%, but I am concerned that the change may introduce a race condition. If 2 users request the page at the same time and the Util object is shared, it's possible that user A's info could be returned to user B, or vice-versa. Thanks in advance, Chris -- Chris Herdt Web Applications Developer http://osric.com/chris/ --001a1134b420ab74420515d5203e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>Does the USE directive load a new instance of the obj= ect per request? Or is it cached?</div><div><br></div>I'm trying to spe= ed up a legacy app that uses TT (which is new to me). I discovered the app = was making numerous identical database calls to retrieve the authenticated = user's info.<div><br></div><div>Each template includes the line [% USE = Util; %] at the top -- it's this class where the user info is retrieved= . I modified Util.pm so that it checks to see if it already has a user prop= erty, checks to make sure the user property contains the same username as t= he requested user, and if so returns that instead of generating a database = call.</div><div><br></div><div>This drops the load time by 75%, but I am co= ncerned that the change may introduce a race condition. If 2 users request = the page at the same time and the Util object is shared, it's possible = that user A's info could be returned to user B, or vice-versa.</div><di= v><br></div><div>Thanks in advance,</div><div>Chris=C2=A0<div><br></div>-- = <br><div class=3D"gmail_signature">Chris Herdt<br>Web Applications Develope= r<br><a href=3D"http://osric.com/chris/" target=3D"_blank">http://osric.com= /chris/</a></div> </div></div> --001a1134b420ab74420515d5203e-- --===============4316817633000181923== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates --===============4316817633000181923==--