Re: [htmltmpl] cache-ing question
Brought to you by:
samtregar
From: Thilo P. <thi...@we...> - 2003-02-14 01:22:41
|
Hi, > I have a mod_perl/CGI::Application program that I've written that > populates > a HTML::Template with a list of files that are on the server. > I'd like to cache that list, based on the URL, so that it doesn't have > to do > a readdir(), grep() and also a TreeBuilder to get the TITLE everytime > someone visits the program. > > Has anyone done something similar and can share any tips? Since you are using mod_perl, you can just create save your result in any variable that stays around. Assuming your data is stored in a hashref (or any other scalar) you could do something like sub get_directory_data{ return $MyCache::DirectoryData if defined $MyCache::DirectoryData; # create the cache my $data = .... do something here ... $MyCache::DirectoryData = $data; return $data; } if you want to refresh your cache after some time, you can also set up a timestamp. > Does the cache-ing in HTML::Template also cache the params? No, and that would be a bad idea, because usually you do not want to have any old params around but start out fresh. > If not, then > what is it cache-ing? Just the template itself? It is caching a parsed instance of the template. Using a cache saves you the time to read the template from the disk and transforming it into the internal parse-tree structure. > If it is, it looks like in > the docs, it caches, based on the filename - so if I'm using 1 > template for > all those lists, then should I break it up into (the number of list > possibilites # {14}) templates? If those 14 have the same HTML and only differ in the content of the parameters, do not break it up. Cheers, Thilo |