AEM Clear Cache Tool for Seamless Testing

T Mrudula Reddy
Activate AEM
Published in
4 min readJan 17, 2024

Introduction

In this fast-paced dynamic web development world, continuous development and testing is pivotal to deliver high quality applications. As a developer, implementing these high-quality applications within the allotted time span without impacting the overall performance is necessary. Alongside, Quality Assurance of the application developed is crucial to test and evaluate its robustness. One common challenge faced during the testing phase in AEM is dealing with the cache related issues. To address this challenge and reduce the gap between the developers and testing teams, a custom cache clear tool can be built on AEM. This tool empowers testing teams to overcome the cache hurdles, ensuring a smooth handover to production process.

The Challenge: Cache woes in the QA process

Quality Assurance is an integral part of the software development lifecycle, and our QA team plays a vital role in identifying the bugs before a product release. However, they often encountered issues related to outdated or stale cache content during their testing phase. This led to the discrepancies between test environments and the developers, causing frustration and delays in the testing process.

Recognizing the impact of cache issues on QA efficiency, the clear cache tool has come into picture. The primary goal was to improve the QA team to work with accurate and up to date data, ultimately enhancing the quality of our software releases.

To address these challenges, our team built a custom cache clearing tool accessible to authors within the AEM environment. This cache clearing tool offers users the ability to specify the path using the path browser menu and clear the cache for the same. Moreover, this tool has the capability to clear both dispatcher as well as Fastly CDN cache, allowing users to manage caching with precision.

Clear Cache Tool

This tool is built in the author environment under the custom tools overriding the /libs/cq/core/content/nav/tools to /apps/cq/core/content/nav/tools and adding our custom tool.

Mention the specific path where the content needs to be invalidated.

Steps:

  1. After overriding the path from libs to apps create a custom tools option and add your custom tools.

Eg: /apps/cq/core/content/nav/tools/custom-tools.

content.xml for the /apps/cq/core/content/nav/tools/custom-tools
content.xml for the page /apps/cq/core/content/nav/tools/custom-tools/clear-cache

2. Create a shell page under the custom project path and add configure the head, title and content.

Eg: /apps/<project-name>/components/content/clear-cache

.content.xml for the custom shell page

3. Under the content container add the inputBox of type — pathfield and submitButton for the dispatcher and submitCDNButton for CDN.

.content.xml for the custom shell page

4. Create a custom clientlibs under your project folder and give a category name “clear-cache.base”.

5. Create a js and add the validations for the field and making an AJAX calls based on click of the buttons on the UI for Clear Dispatcher Cache and Clear CDN Cache.

AJAX call on click of ‘Clear Dispatcher Cache’
AJAX call on click of ‘Clear CDN Cache’

6. Create a SlingHttpServlet to clear the dispatcher and CDN caches.

servlet class

7. For type=Dispatcher add the condition mentioned in the below code snippet.

‘type=Dispatcher’ Invalidation call.

8. For type=CDN, we need the purge_key and the publishHost to clear the CDN cache.

‘type=CDN’ purge call.

Note: The purge key can be requested from the CDN team via support.

Working:

  1. Go to the tools -> custom tools click on the Clear Cache Tool option.
UI for the Custom Shell Page

2. Specify the path that need to be cleared and click on the clear dispatcher cache and clear CDN cache to clear the dispatcher and CDN caches respectively.

Key Features:

· Easy Cache Invalidation.

· User-Friendly Interface.

· Instant Content Reflection.

Benefits:

· Reduce dependency on developers.

· Faster Testing cycles.

· Enhances testing accuracy.

· Improved collaboration.

Conclusion:

In the quest for a seamless and efficient development lifecycle, the cache clear tool for AEM has emerged as a vital asset. By addressing and overcoming cache challenges, we not only improved the efficiency of our QA processes but also laid a foundation for more reliable and robust software releases. This tool reduces the gap between developers and testers, fostering a collaborative and agile environment.

--

--