[Templates] stonehenge.com data/partial HTML caching
Perrin Harkins
perrin@elem.com
Fri, 27 Sep 2002 11:28:01 -0400
Randal L. Schwartz wrote:
> 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;
Interesting. I could add a simple get() option to my cache plugin
prototype to make it cover this. Right now you'd have to do it like this:
[% USE cache = Cache %]
[% cache.include(TEMPLATE => nav_bar, CACHE_VARS => ['class',
'instance', 'global.navbardata.modtime'], TTL => 1800) %]
Your approach of computing the key ahead is more effort in the template,
but it does solve a problem I had, namely how to resolve multi-level dot
notation (global.navbardata.modtime) from a plugin at runtime.
Incidentally, I think that a BerkeleyDB backend for Cache::Cache will
blow away the current file-based one. Computing the file name is
surprisingly slow with Digest::SHA1.
- Perrin