utility_for_dispatcher_cache_flush.png

How to clear the dispatcher cache in AEM as cloud service.

Sep 9th | Varshish Bhanushali


Introduction

Welcome! In today's dynamic digital landscape, delivering seamless and lightning-fast web experiences is paramount. For those leveraging the power of Adobe Experience Manager (AEM) as a Cloud Service, ensuring optimal performance is a continuous focus.

A critical component in achieving this speed and efficiency is the dispatcher, AEM's caching layer. By intelligently storing static content closer to your website visitors, the dispatcher significantly reduces the load on your AEM publish and preview instances, leading to quicker page load times and a smoother user journey.

However, situations inevitably arise where you need to invalidate or "flush" this cached content to ensure users are always seeing the latest updates. This brings us to the necessity of having a robust and efficient utility specifically designed to flush the dispatcher cache for your AEM publish and preview services, a topic we'll delve into in this article.



Understanding Dispatcher Caching in AEM as a Cloud Service

let's consider the different environments within AEM as a Cloud Service: publish and preview. The publish service is what your end-users interact with – it's your live, public-facing website. Performance here is absolutely critical for user satisfaction and SEO. The preview service, on the other hand, is primarily used for internal teams to review and approve content changes before they go live. While performance is still important for a smooth authoring experience, the urgency and scale often differ from the public-facing site.

When it comes to updating your website, you'll often need to clear the dispatcher cache to ensure these changes are reflected for your visitors on the publish environment and for your content authors on the preview environment. Manually clearing this cache can become quite challenging, especially when dealing with both services. This often involves:

  1. Multiple configurations: You likely have separate dispatcher configurations for your publish and preview environments, meaning you need to interact with each independently.
  2. Complexity of invalidation: Determining exactly which parts of the cache need to be cleared after a content update can be intricate. Incorrectly invalidating too much can lead to a sudden surge in traffic to your AEM instances as the cache rebuilds, while invalidating too little means users might still see outdated content.
  3. Lack of centralized control: Without a dedicated utility, tracking and managing cache invalidations across different environments can be cumbersome.

These challenges underscore the need for a more streamlined and automated approach to dispatcher cache flushing, particularly one that caters to the specific requirements of both your publish and preview services.



Implementation Idea to create the Utility

Step 1 : Create the navigation item in AEM tools console.


Implementation Idea to create the Utility

Step 2 : Next, create the dispatcher cache flush utility component. This component will be an actual Coral UI form with the following features: it should accept input paths for cache flushing and include an option to select whether the cache flush applies to the preview or publish service.

The form will look something like below.

Implementation Idea to create the Utility

Step 3 : Next, develop the servlet that will be triggered when the "clear cache" button is submitted. This servlet will receive input paths and the service type (preview or publish) as parameters. It will then utilize the org.apache.sling.distribution.Distributor API to invalidate the cache.

The below code snippet for example showcases how you can use the DistributionRequest API to issue an invalidate AEM Dispatcher cache for a specific set of paths.

DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.INVALIDATE, false, paths);
DistributionResponse dResponse = distributor.distribute(agent, resolver, distributionRequest);

if (!dResponse.isSuccessful()) {
    writer.println(String.format("Error Dispatcher Clear : %s - %s", dResponse.getDistributionInfo().getId(), dResponse.getMessage()));
} else {
    writer.println(String.format("Success Dispatcher Cache cleared successfully for below paths 
%s
", path)); }

Step 4 : Deploy the utility and servlet to your AEM as a Cloud Service instance. To test the utility, simply select the target service for cache flushing and provide the desired path(s). You can then observe the cache invalidation requests in the distribution agent logs.


Implementation Idea to create the Utility
Implementation Idea to create the Utility

Conclusion

Manually clearing dispatcher cache in AEM as a Cloud Service - especially across both publish and preview environments - can be time-consuming and error-prone. But by implementing a custom dispatcher cache flush utility using the Sling Distribution API and AEM’s Coral UI, you can empower your teams to keep content fresh and performance optimal.

This solution brings together convenience, precision, and scalability - allowing you to confidently manage cache across your environments with a few clicks.



Need Help Implementing This in Your AEM Cloud Environment?

If you're looking to streamline dispatcher cache flushing or need help implementing this utility in your AEM as a Cloud Service instance, we’re here to help.

Contact us today to talk with one of our AEM experts - we can help you build and deploy this solution quickly, so your team can focus on delivering great experiences, not troubleshooting stale content.