How to Setup the AEM Dispatcher Flush Agent?

Before setting up the dispatcher flush agent on your AEM publish instance, we must make available the /dispatcher/invalidate.cache URI. Where is exactly the /dispatcher/invalidate.cache endpoint coming from? In this article we will answer how is the /dispatcher/invalidate.cache generated, how do we securely allow only specific IP addresses to make a flush cache request, and how to configure a basic dispatcher flush agent on the publish agent.

This article is written while I had my development environment running, where the AEM publish server and dispatcher apache server are on the same system, similar setup to here. However, the understanding here will be valid for external servers setup.


1. How is the /dispatcher/invalidate.cache generated?

There’s no magic behind the /dispatcher/invalidate.cache endpoint. This endpoint is actually created by the AEM Dispatcher Module. When the Dispatcher Module is enabled on your web server’s VirtualHost the endpoint will be available. However, not anyone can be calling this endpoint where in the next section we will go through how to set up permissions for the this.

Example

1
2
3
4
5
6
7
8
9
10
11
ServerName weretail.com
ServerAlias www.weretail.com
DocumentRoot "${docRootPath}/aem_sites"
<Directory "${docRootPath}/aem_sites">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride None
Require all granted
# enabling the AEM Dispatcher Module

SetHandler dispatcher-handler
ModMimeUsePathInfo On

2. How do we securely allow only specific IP addresses to make a flush cache request?

With a fresh installation of the dispatcher, utilising the dispatcher.any template, there will be a section called allowedClients (all configuration have been commented out in the default configs). The /allowedClients property defines specific clients that are allowed to flush the cache; globbing patterns are matched against the IP.

When the setup is complete, you are now able to make calls to the /dispatcher/invalidate.cache endpoint, for example, http://localhost:80/dispatcher/invalidate.cache. When configuring the Web Server on an external server, making sure that the AEM publish server is whitelisted from the dispatcher server, and the dispatcher.any file from the /allowedClients property is configured.

Example
As an example, we can configure the values here with localhost & 127.0.0.1.

1
2
3
4
5
6
7
8
9
10
11
12
# The allowedClients section restricts the client IP addresses that are
# allowed to issue activation requests.
/allowedClients
{
# deny all clients
/0000 { /glob "*" /type "deny" }
# allow local host connection
/0001 { /glob "127.0.0.1" /type "allow" }
/0002 { /glob "localhost" /type "allow" }
# allow example some AEM publish server
/0003 { /glob "192.168.3.9" /type "allow" }
}





3. How to configure a basic dispatcher flush agent on the AEM publish?

After when steps 1 & 2 from above is completed, we can go straight to our replication agents to publish to configure the dispatcher flush agent. It would be as simple as these simple steps below:
Dispatcher configuration dialogue with the valid URI in the configuration

  1. Visit the configuration page http://localhost:4503/etc/replication/agents.publish/flush.html.
  2. Insert your valid URI in the configuration. (in my case, I will use http://localhost:80/dispatcher/invalidate.cache)
  3. Test the connection to get a connection success status.
  4. Enable the flush agent.
  5. We are done.
  6. Go ahead and activate a page from author to test this out.

When you activate a page from the author environment, your Web Server logs should show something like this :

1
2
3
4
5
6
7
8
9
[Sat Jan 09 21:07:19 2021] [D] [pid 8:tid 139698416600832] Found farm sites for localhost
[Sat Jan 09 21:07:19 2021] [D] [pid 8:tid 139698416600832] checking [/dispatcher/invalidate.cache]
[Sat Jan 09 21:07:19 2021] [I] [pid 8:tid 139698416600832] Activation detected: action=Activate [/content/we-retail/us/en]
[Sat Jan 09 21:07:19 2021] [I] [pid 8:tid 139698416600832] Touched /etc/httpd/httpd_www/aem_sites/.stat
[Sat Jan 09 21:07:19 2021] [D] [pid 8:tid 139698416600832] response.status = 200
[Sat Jan 09 21:07:19 2021] [D] [pid 8:tid 139698416600832] response.headers[Server] = "Communique/2.6.3 (build 5221)"
[Sat Jan 09 21:07:19 2021] [D] [pid 8:tid 139698416600832] response.headers[Content-Type] = "text/html"
[Sat Jan 09 21:07:19 2021] [D] [pid 8:tid 139698416600832] cache flushed
[Sat Jan 09 21:07:19 2021] [I] [pid 8:tid 139698416600832] "GET /dispatcher/invalidate.cache" 200 purge [sites/-] 7ms

Last Notes

Lastly, I just wanted to say that it is best practice to set up the dispatch flush agent on the publish server, as this will eliminate content race conditions; where the content has been successfully replicated to the publish instance, then a content flush is fulfilled.




Was this post helpful?

Hello, I am an Adobe AEM MVP & a certified Lead AEM Developer who is currently working as a Senior AEM Full Stack Developer at Whitbread, UK, London. I have 10 years of overall web engineering experience and 6 years of AEM experience in practice. I hope to give back to the AEM Full Stack Development community by sharing my knowledge with the world.

One thought on “How to Setup the AEM Dispatcher Flush Agent?

Leave a Reply to Robert Cancel reply

Your email address will not be published. Required fields are marked *

Back To Top