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 » Developer » Cache in custom view

Cache in custom view

Cache in custom view

Saturday 26 May 2012 7:17:03 pm - 2 replies


In a custom module/view, i would like to add cache in my template. I tried to add a cache-block however I cannot find a method in the API to clear the cache-block knowing its keys.

Is this normal ? I know that the cache-block function should be used in the pagelayout however i cannot find another way to cache a custom view template. Is there a way ? With clear cache functionnality ?

Thanks in advance

Sunday 27 May 2012 1:13:59 pm

Unfortunately, there is currently no way to clear a single cache-block's cache. You could code one of your own, but it's not easy.

The best other developers have come up with is:

- add a specific html comment in your tpl, inside the cache block

- grep for that piece of text in the cache-block cache directories and delete all files that match

Quite hackish, as you can see (and it needs different code to work in cluster mode)

This is, afaict, a byproduct of the way cache blocks cache files are stored in the filesystem.

There is a (currently pending) pull request to reorganize the way that cache blocks are stored, that would pave the way to single-cache-block cleanup functionality.

If you want to use the caching API from within your view's php code instead of using tpl cache blocks, you might have better chances at cleaning up your caches...

Sunday 27 May 2012 1:57:19 pm

Yeah, after some research, i came up with the same solution you explained : using the cache in php code. I didn't find the first one with the HTML comment. I think it is the easiest one to implement but you are right it is a hack.

I think, i wil try to rewrite the way i generate template to add my custom cache manager in the view php code and use the Cache module in the zeta components.



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

36 542 Users on board!

Forums menu

Proudly Developed with from