Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to manage dispatcher cache invalidations with a reference type component

Avatar

Level 2

We are looking to create/use a reference type component, my question is what process have people used before to manage dispatcher cache invalidation for when the component that has been referenced is updated to ensure that all pages where it has been referenced on are also invalidated on the dispatcher? asking users to republish these pages manually is not really an option for us.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

if you are using a boilerplate approach to maintain all your content for reference component, then here is what you can do;

  • bind activation event listener to activation of just that boiler plate.

Refer following article for more details around replication listener - https://helpx.adobe.com/experience-manager/kb/ReplicationListener.html

  • find pages that contains reference component pointing to boiler plate content.
  • programmatically issue dispatcher flush for all those pages.

Reference code for programmatically flushing the cache:

            PostMethod post = new PostMethod("http://localhost:80/dispatcher/invalidate.cache");

            post.setRequestHeader("CQ-Action", "Activate");

            post.setRequestHeader("CQ-Handle",handle);

 

            if (StringUtils.isNotBlank(pagePath))

            {

                StringRequestEntity body = new StringRequestEntity(pagePath,null,null);

                post.setRequestEntity(body);

                post.setRequestHeader("Content-length", String.valueOf(body.getContentLength()));

            }

 

Above code does what dispatcher flush agent does, it basically issues programmatic cache-flush request for specific pagePaths

Hope this helps :)

- Runal

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

if you are using a boilerplate approach to maintain all your content for reference component, then here is what you can do;

  • bind activation event listener to activation of just that boiler plate.

Refer following article for more details around replication listener - https://helpx.adobe.com/experience-manager/kb/ReplicationListener.html

  • find pages that contains reference component pointing to boiler plate content.
  • programmatically issue dispatcher flush for all those pages.

Reference code for programmatically flushing the cache:

            PostMethod post = new PostMethod("http://localhost:80/dispatcher/invalidate.cache");

            post.setRequestHeader("CQ-Action", "Activate");

            post.setRequestHeader("CQ-Handle",handle);

 

            if (StringUtils.isNotBlank(pagePath))

            {

                StringRequestEntity body = new StringRequestEntity(pagePath,null,null);

                post.setRequestEntity(body);

                post.setRequestHeader("Content-length", String.valueOf(body.getContentLength()));

            }

 

Above code does what dispatcher flush agent does, it basically issues programmatic cache-flush request for specific pagePaths

Hope this helps :)

- Runal