Wednesday 03 December 2003 5:31:57 am
Hi Marco, It's very true that good documentation is lacking on the use of cache-block. I have just been investigating it and here is what I found (please correct me, anyone if this is wrong, it would be useful for both me and others) The cache-block directive caches that block of code and everywhere it is used in a template, the faster, cached version is used. This is all well and good if you have content which doesn't change, but gets more complicated when it does. So, in the case of a menu; If you have the same menu on every page, then you can just use cache-block without setting a keys variable and it should work fine. If you have a 2 level nested menu like;
contact
projects
---- project 1
---- project 2 other and the second level depend which node you are looking at, you need to use the keys variable to cache a different chunk of code for each instance of this. So, in this case, if you were using $module_result.node_id to determine which sub menu to expand, you would do the following;
{cache-block keys=$module_result.node_id}
{code goes here} {/cache-block} which will cache a different version of this block for every node. Going one step further (which I haven't yet, but still) if you have a section of code which is dependent upon two variables for it's output, you use both of these as the key, e.g. if it is dependent upon $module_result.node_id and $user (or whatever the variable which has the current user - I can't recall). You would do;
{cache-block keys=array($module_result.node_id, $user)}
{code goes here} {/cache-block} I have just implemented cache-block on my site and it speeded up server response times considerably. Well worth doing. Anyway, hope this helps (and was correct)
All the best, Ben Pirt
|