eZ Community » Forums » Setup & design » Advanced caching question: clearing...

Advanced caching question: clearing the reverse_related parents cache

Advanced caching question: clearing the reverse_related parents cache

Thursday 22 December 2011 2:16:20 pm - 4 replies

Hi. I have a project where a product class has image objects in a relation attribute. When an image is changed, the product's full view cache is cleared using the SmartCacheClear settings in viewcache.ini. This works.

However, the product is also used in a line view of the parent node (in this case a folder). In the full view of this parent I still see the old image, hence it's cache has not been cleared.

Is there any way to expire the parents of the reverse related object's nodes as well?

Modified on Thursday 22 December 2011 2:18:42 pm by Sander van den Akker

Thursday 22 December 2011 7:28:01 pm

Hi !

The problem is that object expired by SmartCacheClear rules don't have those rules applied to them.

I don't think you have an "out of the box" solution for this.

You may :

 - Use multipositioning for images as child of products instead of objectrelation

 - Use a custom workflow to trigger what ever you want to when an image is updated

 - Use a custom edit handler for images (same as the worflow solution)

 - Hack eZContentCacheManager to make it more customizable via config and/or handlers and share your work with the community happy.gif Emoticon


We had a Similar discussion over here but with no immediate solution...

Friday 23 December 2011 2:06:22 pm

Hello Sander,


I think the solution I would very quickly implment to put this issue to rest would be a custom workflow event.


Infact I've done this exact solution before more than once.


You can take a look at how to do this (ruffly) by taking a look at a similar snippet of code from a recent extension we published publicly.



I think the following are helpful related keys to consider (again, just my thoughts here)


  • Only run workflow event when needed. This means if using 'content, publish' based triggers use a multiplexer (only as needed) to only say run the workflow event if an image class object is published (which includes your updates as well).


  • Plan for failure: Check the object class and end the workflow event execution if the above requirement is missed for some reason. This is slower as more code is run in this situation but we at BC usually prefer to double check within a workflow event that the usage requirements are maintained rather than have future errors be encountered. We think this is a strongly recommended programming best practice. 


I think it might work like this.

  • Fetch object by id (image object being updated, but only if needed)
  • Fetch all reverse related objects
  • Iterate over array of all reverse related objects and clear their caches. 
    • This is the most painless part of the process.



If you (or someone else) needs help in creating their first workflow event, this related blog might be helpful. 




If you have any questions about some of my comments, please feel free to ask happy.gif Emoticon


Happy Holidays!


I hope this helps ...




Modified on Friday 23 December 2011 2:42:58 pm by // Heath

Thursday 29 December 2011 12:53:40 pm

Thanks for your suggestions folks, I went with a custom workflow trigger happy.gif Emoticon

Thursday 29 December 2011 8:44:55 pm

Hello Sander,


Thank you for sharing the solution you chose to use to solve your requirements / needs back with the community!


I hope this helps other users looking for a similar solution in the future.


Update: I update my latest post in this thread to add a helpful reference to the thread in the interests of newer eZ Publish users and developers who have not learned that you can very easily create custom workflow triggers with virtually -any- eZ Publish based PHP code (constructs and contexts, to hear more read the blog post comments in full, http://share.ez.no/forums/discussions/tip-custom-workflow-operation-triggers#comment71022 ).

If you would like to learn how you too can create and use custom workflow triggers within your custom eZ Publish PHP code, take a few minutes to read and test the direct and clear howto based tip shared in the following blog link, http://share.ez.no/blogs/thiago-campos-viana/tip-custom-workflow-operation-triggers 




Modified on Thursday 29 December 2011 11:34:04 pm by // Heath


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

36 542 Users on board!

Forums menu

Proudly Developed with from