Showing posts with label Cache. Show all posts
Showing posts with label Cache. Show all posts

Tuesday, 22 November 2016

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 (Which ever 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.