This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » General » Cache-block strategy

Cache-block strategy

Cache-block strategy

Wednesday 23 April 2014 3:22:59 pm - 3 replies

Hi to all blunk.gif Emoticon

I need help with cache blocks!

So, on my view-full templates, I often include a template named pub.tpl that displays banners (a very simple code that fetch banners nodes into a folder located somewere in the treenode).

Insofar as the banners are located "far" in the tree, when banners are published, the cache for the various view-full in which I made an include of pub.tpl is not updated and I end up with false html pages. 

My first idea was to disable viewcaching on view-full in which I include pub.tpl to encapsulate the call of pub.tpl in a cache block. 

The problem is that suddenly my pages pass from 1 SQL query to 15 ! and while all the code in my view-full is in cache-blocks (3 cache-blocks exactly).

Would you have another solution? 

PS: I do not think using viewcache.ini is relevant because not precise enough: it will clear node viewcache of 90% of nodes at each publication of a banner...

Wednesday 23 April 2014 3:57:59 pm

There are more ways how to do this, but neither is very straightforward. 

  • you approach by disabling view cache is simple but slows down things, I would not recommend it
  • you could leave the cache enabled and trigger the clear via relation. AFAIK, by default, reverse related relations are cleared when you change an object, so you can use that when the banner node is edited, but you need to have relations between that node and all the node where you want to clear the view cache
  • you can also clear the cache for the nodes you mention from cronjob more frequently
  • or you can set the viewcache TTL in the full tpl with e.g. {set-block scope=root variable=cache_ttl}3600{/set-block}
  • or just throw out the pub.tpl form the full view and call it from pagelayout (somehow place it on the full view via CSS), that is maybe the best option if feasible

Wednesday 23 April 2014 4:12:37 pm

Hi Seb, You can disable the cache of your view with the following code 

 {set-block scope=root variable=cache_ttl}0{/set-block}

then open a cache block 

{cache-block keys=$node.node_id subtree_expiry=$node.node_id expiry=0}
     <!--code of your view-->
{include uri='design:example/parts/banners.tpl'}
{cache-block keys=$node.node_id subtree_expiry=$node.node_id expiry=0} 
      <!--code of your view -->


Modified on Wednesday 23 April 2014 4:21:32 pm by patrice brun

Sunday 04 May 2014 5:06:50 pm


Thanks blunk.gif Emoticon but this is already what I tried and it causes too much SQL queries per page (15) !


Finally, since the banners are very infrequently changed (less than 1 time a month), I will clear the caches via cronjob or content edit handler just after their publication.

Solved blunk.gif Emoticon

Modified on Sunday 04 May 2014 5:07:39 pm by Sébastien Antoniotti


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from