Forums / Developer / clear cache within template

clear cache within template

Author Message

Emmanuel Averty

Thursday 30 June 2011 7:02:43 am

Hi,

I wrote a template that fetch a lot of objects. For each one, I must display one of its attribute, so I use data_map template attribute.

Problem : each time I call data_map attribute of my objects, eZ Publish seems to cache those data into a global PHP variable. This variable grows until the PHP script dies due to memory exceed limit.

Question : Is there a way to clean the object cache within a template like I can do in PHP (eZContentObject::resetDataMap() or eZContentObject::clearCache()) ?

Thanks

Joe Kepley

Thursday 30 June 2011 8:19:54 am

Unfortunately, even if you could clear the global while rendering the template, you would likely wind up with a lot of unexpected problems as a result. 

Your best bet is to increase PHP's memory_limit setting. You can also use cache-blocks and the View caching system to keep the memory usage down on subsequent requests.

Does that help?

Marko Žmak

Thursday 30 June 2011 4:45:46 pm

The only way I see is to create template operators that do such stuff.

Also you should rethink why are you fetching a lot of objects on one page... is this really needed and can it be done in some other way?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Emmanuel Averty

Thursday 30 June 2011 11:39:37 pm

Thank you both for your replies.

@Joe : I don't want to increase PHP's memory_limit. It is already high.

@Marko : Yes I must display all these objects data. But you're right I will write my template in a new way : I'll do the fetch stuff in a php module which could clear cache and then transmit only what's needed threw template variables.

Thanx again