On 1/21/2010 2:26 AM, Tobias Kremer wrote: > I was just wondering if it would theoretically be possible to extend > Template::Toolkit to allow something like the following: > > [% CACHE key => 'latest-stories' ttl => '3600' %] > ... Expensive calculations go here ... > [% END %] > > I'm aware of Template::Plugin::Cache, but I don't like the fact that > fragments I'd like to cache have to be included. I'd rather have > fragments take care of caching themselves, like Mason's cache_self() > method. > > On a side note, Template::Plugin::Cache seems to have problems with > Memcached and UTF-8 because the UTF-8 flag is not set on content > retrieved from the cache. This should be easy to fix with something > like: Encode::_utf8_on( $result ); > > What do you think? And how, if possible, would you go about implementing this?
I worked up a system that does this with code similar to this: ---------------------- [% BLOCK foo_block %] stuff to cache here. [% END %] [% api.cached_block(block => 'foo_block', key => 'filename_foo_block', ttl => ) %] ---------------------- cached_block is a routine that has access to the TT context via global variable or at least a variable in the same scope. Then you can simply process the block using the block name when it isn't in the cache. -- Josh _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates
