April 26, 2020
Estimated Post Reading Time ~

Hooking to Cache Invalidation in AEM 6.1

If you need to implement custom cache invalidation based on some event, you can write a workflow service or servlet (Whichever suits best to your requirement). In this Java class you can write code to handle this. The OOTB Flush Service can be utilized for this purpose-

import com.adobe.cq.social.ugcbase.dispatcher.api.FlushService;
@Reference
FlushService flushService;

Then you can simply request a cache invalidation for the corresponding page-
flushService.sendFlushUrl("userId",
FlushService.FlushType.IMMEDIATE_FLUSH, resourceUrl,
FlushService.RefetchType.IMMEDIATE_REFETCH,
new String[] { resourceUrl });

Here resourceUrl is the path of the page without html extension.

In order to make the flush service working properly, create flush agents for each dispathcer with following additional settings-
1. Set the Request method - "POST" because this service expects a POST method flush agent.
2. Send additional parameter for "resource only replication"

-To debug any issues you can add a custom logger from OSGi configurations console on this package-
com.adobe.cq.social.ugcbase.dispatcher.impl.FlushServiceImpl

ACM AEM Commons tool also provides options to help implementing cache invalidation for you through OSGi configurations.
Read More


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.