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

Sunday, 6 January 2019

Backend forbids caching, sent: 'Dispatcher: no-cache'

When using dispatcher if we use below code then pages will not be cached in dispatcher. Error in dispatcher.log is "Backend forbids caching, sent: 'Dispatcher: no-cache'"

response.setHeader("Dispatcher", "no-cache");                       
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setDateHeader("Expires", 0);

Wednesday, 23 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-

    FlushService flushService;

Then you can simply request a cache invalidation for the corresponding page-
                    FlushService.FlushType.IMMEDIATE_FLUSH, resourceUrl,
                    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-

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