Thread: [htmltmpl] inconsistent file_cache behavior
Brought to you by:
samtregar
From: Nishikant K. <nk...@we...> - 2004-05-16 12:44:15
|
I just started using file_cache and am seeing some unexpected behavior. Here is how I am using it. The home page has a block 'Featured Links' which displays a set of default links. If the user is logged in, he gets an additional link 'Customize' that enables him to customize these links and if he chooses do so, the customized links show up in the block instead of default ones. Looks like, the 'Featured Links' block is behaving inconsistently i.e. sometimes after I log out, I continue to see the customized links. At other times, even after I log in, I still see the default links. Apparently, 'featuredLinks.cgi' is returning the template from the cache when I expect it to generate a new one. This is how I am calling the template: my $tmpl = HTML::Template->new(filename => $linksTmpl, file_cache => 1, file_cache_dir => 'tmplCache', file_cache_dir_mode => 0777); Another issue, though not a big one. Even though I specify '0777' for creating file_cache_dir, I still get 'tmplCache' created with '0755' permissions. Thanks Nishi |
From: Sam T. <sa...@tr...> - 2004-05-16 16:29:59
|
On Sun, 16 May 2004, Nishikant Kapoor wrote: > Apparently, 'featuredLinks.cgi' is returning the template from the cache > when I expect it to generate a new one. This is how I am calling the > template: > > my $tmpl = HTML::Template->new(filename => $linksTmpl, > file_cache => 1, > file_cache_dir => 'tmplCache', > file_cache_dir_mode => 0777); What do you mean by 'generate a new one'? Are you auto-generating your templates in some way? Usually templates are edited by hand and the file_cache only refreshes when the mtime on the file changes due to an edit. > Another issue, though not a big one. Even though I specify '0777' for > creating file_cache_dir, I still get 'tmplCache' created with '0755' > permissions. Huh, that's odd. I'm passing that mode as the second arg to mkdir(). That should work. Are you sure you didn't create the directory yourself? -sam |
From: Nishikant K. <nk...@we...> - 2004-05-17 03:47:44
|
Sam Tregar wrote: > On Sun, 16 May 2004, Nishikant Kapoor wrote: > >>Apparently, 'featuredLinks.cgi' is returning the template from the cache >>when I expect it to generate a new one. This is how I am calling the >>template: >> >> my $tmpl = HTML::Template->new(filename => $linksTmpl, >> file_cache => 1, >> file_cache_dir => 'tmplCache', >> file_cache_dir_mode => 0777); > > > What do you mean by 'generate a new one'? Are you auto-generating > your templates in some way? Usually templates are edited by hand and > the file_cache only refreshes when the mtime on the file changes due > to an edit. I meant that the template should get re-filled with default links when I log out rather than returning customized links (which were displayed when I was logged in). I do edit the template by hand but in this case, the mtime on the template is not changing. However, the content for the template needs to change based on whether the user is logged-in or logged-out. >>Another issue, though not a big one. Even though I specify '0777' for >>creating file_cache_dir, I still get 'tmplCache' created with '0755' >>permissions. > > > Huh, that's odd. I'm passing that mode as the second arg to mkdir(). > That should work. Are you sure you didn't create the directory > yourself? Yep, I made sure of that by removing 'tmplCache' and letting H::T create it. Thanks Nishi |
From: Sam T. <sa...@tr...> - 2004-05-17 03:58:04
|
On Sun, 16 May 2004, Nishikant Kapoor wrote: > I do edit the template by hand but in this case, the mtime on the > template is not changing. However, the content for the template needs to > change based on whether the user is logged-in or logged-out. Well that has nothing to do with the file cache. To convince yourself, turn it off and observe that nothing changes! The file cache is just saving HTML::Template the trouble of loading the template from disk every time it needs it. It has nothing to do with the output - that's driven by your calls to param(), which are reset after every new(). > > Huh, that's odd. I'm passing that mode as the second arg to mkdir(). > > That should work. Are you sure you didn't create the directory > > yourself? > > Yep, I made sure of that by removing 'tmplCache' and letting H::T create it. Interesting. Maybe mkdir() is broken on your system. I don't know why that would be... -sam |
From: Nishikant K. <nk...@we...> - 2004-05-17 05:50:42
|
Sam Tregar wrote: > On Sun, 16 May 2004, Nishikant Kapoor wrote: > >>I do edit the template by hand but in this case, the mtime on the >>template is not changing. However, the content for the template needs to >>change based on whether the user is logged-in or logged-out. > > > Well that has nothing to do with the file cache. To convince > yourself, turn it off and observe that nothing changes! The file > cache is just saving HTML::Template the trouble of loading the > template from disk every time it needs it. It has nothing to do with > the output - that's driven by your calls to param(), which are reset > after every new(). Okay, here is what I think is happening. index.shtml: ... <!--#exec cgi="/cgi-bin/featuredLinks.cgi"--> ... When you login or logout, sub showHome() is called. sub showHome { ... my $filter = sub { my $textRef = shift; my $strToReplace = 'featuredLinks.cgi'; if ($$textRef =~ /(.*cgi=\")(.*$strToReplace)(\".*)/) { my $strToReplaceWith = &getFeaturedLinks; $$textRef =~ s/(.*cgi=\")(.*$strToReplace)(\".*)/$strToReplaceWith/g; } }; my $template = HTML::Template->new(filename => 'index.shtml', file_cache => 1, file_cache_dir => 'tmplCache', file_cache_dir_mode => 0777, filter => $filter); ... } #end of showHome() When file_cache is ON, template is being returned from the cache, thereby bypassing the $filter which is actually responsible for getting the appropriate data based on user's login status and hence, the inconsistency. Does this look like what is going on here? If so, what would you suggest be the workaround? Thanks, Nishi |
From: Mathew R. <mat...@re...> - 2004-05-17 06:07:36
|
try 'perldoc HTML::Template' then search for filter... the first thing = it says is: filter - this option allows you to specify a filter for your template files. A filter is a subroutine that will be = called after HTML::Template reads your template file but before = it starts parsing template tags. thus, filtering is only applied on file load (ie when the tamplate is = parsed for tags). Since caching wont allow the file to reload unless it = changes, the filer is not re-applied. To solve this, you can either: a) disable caching if you want to keep the filter b) re-implement the template so that you dont need to use a filter, by = using TMPL_IF and TMPL_INCLUDE Hope this helps, Mathew ----- Original Message -----=20 From: "Nishikant Kapoor" <nk...@we...> To: "T Mailing List" <htm...@li...> Sent: Monday, May 17, 2004 3:56 PM Subject: Re: [htmltmpl] inconsistent file_cache behavior > Sam Tregar wrote: > > On Sun, 16 May 2004, Nishikant Kapoor wrote: > >=20 > >>I do edit the template by hand but in this case, the mtime on the > >>template is not changing. However, the content for the template = needs to > >>change based on whether the user is logged-in or logged-out. > >=20 > >=20 > > Well that has nothing to do with the file cache. To convince > > yourself, turn it off and observe that nothing changes! The file > > cache is just saving HTML::Template the trouble of loading the > > template from disk every time it needs it. It has nothing to do = with > > the output - that's driven by your calls to param(), which are reset > > after every new(). >=20 > Okay, here is what I think is happening. >=20 > index.shtml: > ... > <!--#exec cgi=3D"/cgi-bin/featuredLinks.cgi"--> > ... >=20 > When you login or logout, sub showHome() is called. >=20 > sub showHome { > ... > my $filter =3D sub { > my $textRef =3D shift; >=20 > my $strToReplace =3D 'featuredLinks.cgi'; > if ($$textRef =3D~ /(.*cgi=3D\")(.*$strToReplace)(\".*)/) { > my $strToReplaceWith =3D &getFeaturedLinks; > $$textRef =3D~ = s/(.*cgi=3D\")(.*$strToReplace)(\".*)/$strToReplaceWith/g; > } > }; >=20 > my $template =3D HTML::Template->new(filename =3D> 'index.shtml', > file_cache =3D> 1, > file_cache_dir =3D> 'tmplCache', > file_cache_dir_mode =3D> 0777, > filter =3D> $filter); > ... > } #end of showHome() >=20 > When file_cache is ON, template is being returned from the cache,=20 > thereby bypassing the $filter which is actually responsible for = getting=20 > the appropriate data based on user's login status and hence, the=20 > inconsistency. Does this look like what is going on here? If so, what=20 > would you suggest be the workaround? >=20 > Thanks, > Nishi >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: SourceForge.net Broadband > Sign-up now for SourceForge Broadband and get the fastest > 6.0/768 connection for only $19.95/mo for the first 3 months! > http://ads.osdn.com/?ad_id=3D2562&alloc_id=3D6184&op=3Dclick > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |
From: Mathew R. <mat...@re...> - 2004-05-17 04:08:55
|
> Sam Tregar wrote: > > On Sun, 16 May 2004, Nishikant Kapoor wrote: > >=20 > >>Apparently, 'featuredLinks.cgi' is returning the template from the = cache > >>when I expect it to generate a new one. This is how I am calling the > >>template: > >> > >> my $tmpl =3D HTML::Template->new(filename =3D> $linksTmpl, > >> file_cache =3D> 1, > >> file_cache_dir =3D> 'tmplCache', > >> file_cache_dir_mode =3D> 0777); > >=20 > >=20 > > What do you mean by 'generate a new one'? Are you auto-generating > > your templates in some way? Usually templates are edited by hand = and > > the file_cache only refreshes when the mtime on the file changes due > > to an edit. >=20 > I meant that the template should get re-filled with default links when = I=20 > log out rather than returning customized links (which were displayed=20 > when I was logged in). >=20 > I do edit the template by hand but in this case, the mtime on the=20 > template is not changing. However, the content for the template needs = to=20 > change based on whether the user is logged-in or logged-out. This sounds like you are using H::T incorrectly... somewhere in you = template you should probably doing somthing like: <TMPL_IF logged_in> <TMPL_INCLUDE logged_in.tmpl> <TMPL_ELSE> <TMPL_INCLUDE default.tmpl> </TMPL_IF> You may need to put more information in the email, as it appears that = what you are trying to do, is reasonably simple thus you shouldn't = really be getting stuck. >=20 > >>Another issue, though not a big one. Even though I specify '0777' = for > >>creating file_cache_dir, I still get 'tmplCache' created with '0755' > >>permissions. > >=20 > >=20 > > Huh, that's odd. I'm passing that mode as the second arg to = mkdir(). > > That should work. Are you sure you didn't create the directory > > yourself? >=20 > Yep, I made sure of that by removing 'tmplCache' and letting H::T = create it. This could be related to your 'uname' mask - if it is set to '022' then = you have found your answer. Mathew |