[Templates] Caching Output of Components

Josh Rosenbaum josh@infogears.com
Thu, 10 Aug 2006 10:48:08 -0600


Bill Moseley wrote:
> On Sun, Aug 06, 2006 at 09:01:32PM -0500, Jonathan Rockway wrote:
[SNIP]
> I didn't want to use different URLs to display two versions of the
> same page.  So I'm not sure if there's a better way to cache them.
> It's not that slow, but it does seem a shame to have to rebuild the
> page every request, when the vast majority of the requests will be
> from users that are not logged in so the page is always the same.
[SNIP]

I haven't used the caching solutions you have mentioned, however, if you could make the username part of the cache key, you should be able to do this easily.

One solution we've used is to enable cacheable blocks that use the username or other parameters as part of the cache key.

ie:
[% BLOCK xyz %]
bunch of code here
[% END %]
[% cached_section('xyz', "/mykey/$username", 'period_here') %]

The block will only be processed in the cached_section routine if there is a cache miss.

-- Josh