OK, that was easier than I thought. I added
package Stonehenge::Template::Plugin::CacheFileCache;
use Cache::FileCache;
use base qw(Template::Plugin);
sub new {
my $class = shift;
my $context = shift;
Cache::FileCache->new(@_);
}
1;
to my webserver's mod_perl search path, and
TT2PluginBase Stonehenge::Template::Pluginto my config file, and now I can say:
USE mycache = CacheFileCache({
namespace => 'stonehenge-nav_stacked_bars',
default_expires_in => 1800,
auto_purge_interval => 1800,
});
mykey = [class, instance, global.navbardata.modtime];
mykey = mykey.join(":");
result = mycache.get(mykey);
UNLESS result;
result = BLOCK;
[[ stuff to compute result deleted ]]
END;
mycache.set(mykey, result);
FILTER stderr; "cache miss on "; mykey; "\n"; END;
END;
result;
to my navbar generation template, and I've just cached the creation of my navbars (function of class, instance, and the timestamp on the navbar data).
TT2 rocks. Cache::Cache rocks. 'nuff said.
Is there an article coming on using TT and caching and filters? go on you know you want to
Re:so the second codeblock goes in the template?
merlyn on 2002-09-27T18:38:18
The third code block goes into the template. The second code block was a line for the httpd.conf file.