Cache on WeakReference

  Written by The Jahia Team
 
Developers
   Estimated reading time:

When you have weakreference field on a content (for instance related events on a publication, and the events should display the publication) and you change the weakreference to another event the cache is not flushed. Scenario:

  • flush cache site
  • reference event1 on my publication1
  • publish
  • go to event1 page and my publication1 is displayed (Ok)
  • reference event2 on my publication1
  • publish
  • go to event1 page and my publication isn't displayed (Ok)
  • go to event2 page and my publication isn't displayed (Ko)
     

Answer

The problem is the second source is already cached and a publication of the weakreference don't flush the cache because the cacheDependeny is set to late (just on the first call of the weakreference).
A solution for this would be to add a simple drools rule to flush the related cache like:

rule "flush related event cache"
 salience 25
 when
 A node is published
 - the node has the type jnt:publication
 then
> if (node.getNode().getProperty("relatedEvent") != null ) {
> org.jahia.services.cache.CacheHelper.flushOutputCachesForPath(node.getNode().getProperty("relatedEvent").getNode().getPath(), true);
> }
end 

 

Related links