Memcache and Smarty

Rob Sharp at
Mon Sep 10 13:35:58 UTC 2007

> On 10 Sep 2007, at 08:50, Rob Sharp wrote:
> > Smarty will compile each of these sections individually and then
> > cache the page as a whole. There's not currently (AFAIK)
> > template-level caching in Smarty, but one of my co-workers has a
> > working implementation that we're testing.
> That's not true. Smarty caches whole templates, but one template can
> be included in another, hence you can get selective caching of page
> elements. Read the docs carefully as it's quite
> fiddly:
> In particular notice {insert}, and also that plugins can choose
> whether their output is cached.

Ah, I see what you mean. We use include in preference to fetch - for
variable scoping reasons - and that means we only have page-level
caching. Obviously using fetch has the caching advantage, but requires
explicit variable assignment over a global scope.

Back to memcache, this is a smarty example of the plugin we're using to
cache templates in memcache:

    {cacheBlock cacheHashData=$digestItem timeout=60

'cachehashData' is both passed into the template, and used to uniquify
the key, and 'include' is the template to load

It's very simple, but solves a common problem for us. Ideally the TTL
would be abstracted from the templates, but this is a 10 minute fix
that's still under development. We've yet to benchmark, but the template
in question is incredibly data-intensive (it retrieves activity digest
data for a given user), so it works a treat for our situation.

Is anyone using something similar, or have a better approach to that


> Marcus
> -- 
> Marcus Bointon
> Synchromedia Limited: Creators of
> UK resellers of info at hand CRM solutions
> marcus at |

Rob Sharp
Development Lead 

telephone: 02 9282 4038
facsimile: 02 9282 4099
skype: qu4nnum

Sound Alliance 
inthemix : FasterLouder : Thought By Them : SameSame

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the memcached mailing list