AEM Solution: How to Clear dispatcher cache by myself?

In any web application, The caching has significant value in the overall performance of the application. But, At the same time, Developers like to test their changes & able to clear the cache frequently. The caching of AEM CMS content caching happens two places: Web Server (i.e apache) & CDN (i.e Akamai) Server. However, AEM comes with dispatcher module within the webserver to handle caching request coming from AEM author environment.

Basically, Whenever content author activates any content page path from AEM author environment, A HTTP request goes to AEM publish server to trigger an event for another HTTP push request to the dispatcher module (via web server). This dispatcher push request purge the cache of a requested path by changing the timestamp of state file. Anyway, An explanation isn’t required about how dispatcher works? We can skip that part.

AEM Cache clearing totally depends on content paths & type of the pages. For example, if you want to clear the cache of any AEM Page / Image, you can just publish the same AEM Page / Image from AEM author & cache gets refreshed provided dispatcher module is configured on the publishing server.

Problems in cache clearing

It may seem easy clearing the cache of AEM Pages & Assets. In the following cases, It is very problematic in many cases. Some of them listed here.

  • Clearing the cache of Javascript minified file. Path of the file & client libs does not match at all.
  • Clearing the cache of a content request which is a servlet path but do not existing in real content hierarchy. /bin/myapp/servlet/abc.html
  • Clearing cache of vanity url.
  • Clearing cache of url which has different path but AEM mapping helps to resolve the path. For instance, Live url is /myapp/abc/xyz.html but content hierarchies are /content/myapp/en/1/abc/xyz.html

What are the traditional solutions?

  • Ask someone who has access to login to web server & clears the cache manually. But here is the catch. How many times you can ask for it if you are testing your javascript code.
  • Run curl command to clear the cache but for this, You need to know web servers dispatcher IP/ domain etc. And if there are multiple web servers then you have to clear the cache of one server at a time.
  • Run Jenkins job which may clear all the cache. And it could be problematic if you do it in stage or prod.

Easiest Solution

All the above problems are not that bad & there are solutions to it. However, As a developer, I would like to have quick & an easy way to clear the cache by myself. The AEM dispatcher module purges the cache based on the path. And to use this feature, You can clear the cache of any file/Path/Assets. Following below steps to clear cache without anyone help.

Let’s take an example of purging the cache of your minified javascript file. Path of the file is/etc/designs/myapp/core.mini.js

  • Create a file with the same name & path.
  • Activate the same file.
  • The Dispatcher would update the cache file & start referring to your dummy file found as a new file.
  • De-activate the same dummy file right away. This is required because Your dummy file will not have correct content or code. So, Make sure you de-activate the same file again.
  • Once the file is de-activated, ClientLibs or AEM path resolution will happen as normal.
  • You can delete the same file in the author for future purpose or you can delete it.

Above solution works with any other path or file. Be it a JSON, XML, HTML etc. The only condition is that the path which you want to clear from the cache has to be created in the author first.

Finally Thoughts

These solutions are tested but can’t say that it solves all the problems. You can post your queries in the comment section. Will look into those & revert back.

Advertisements


Categories: Adobe AEM, Adobe CQ, AEM CMS, AEM Solutions

Tags: , , ,

1 reply

  1. Very helpful for the developers.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.