April 7, 2020
Estimated Post Reading Time ~

Enable dispatcher caching for flat structured URL

We had an interesting problem to solve within AEM where most of our pages are public/non-authenticated pages and its a flat structured URL. Something like http://yourdomain.com/firstslash/abcxxxxx (vanity URLs). All the “x” (in our case its numbers) are the ones that will vary from page to page. We have to enable caching for this URL in dispatcher and any update to one of the pages should not invalidate the cache for other pages.

Our infrastructure composition:
  • AEM version: 5.6.1
  • Dispatcher version: 4.1.5
  • Apache version: 2.2.3
  • OS: Redhat 5.11
Our content structure on CQ

/content/<basefolder>/<language>/<pagecategorytype>/abcxxxxx

Our vanity url structure

/firstslash/abcxxxxx

There could be multiple ways of approaching the solution and we took the below route to cater the solution for us

We slightly tweaked our application structure illustrated below (only dispatcher and publisher connectivity)



We had applied a few apache rules on both the apache’s (one in dispatcher and one in publisher) to create a virtual folder for us to do the caching. I am starting the solutioning here

1) Configure your dispatcher.any file to invalidate the cache starting from the second (from the base) subfolder. Below is the entry to be updated

statfileslevel “2”

2) Configure your publisher’s apache to be requested for any customer request from the dispatcher in your dispatcher.any file under the “renders” section.

3) Now add the below rules in your dispatcher apache to send the request with the virtual folder added to the request path.

RewriteCond %{REQUEST_URI} ^/firstslash/abc([0-9]+)$
RewriteRule ^/firstslash/(.*)$ /firstslash/$1/$1.html [PT]

4) Add the below rules in the publisher’s apache to process the request with the virtual folder and convert it to the normal request before it gets requested to the publisher’s CQ app.

RewriteCond %{REQUEST_URI} ^/firstslash/abc([0-9]+)(.*)$
RewriteRule ^/firstslash/abc([0-9]+)(.*)$ /firstslash/abc$1 [PT,L]

5) So far we have set up the caching at a second subfolder level in the dispatcher. Now in the publisher replication frontend, please add the below CQ actions and also enable triggering invalidate cache from publisher.



6) Now as the last step, we have to invalidate the cache only for the specific page based on activation. For this we have to edit the header when the invalidate request has been sent from the publisher to dispatcher. Add the below rule to the dispatcher based on your requirement (refer our content structure)

RequestHeader edit CQ-Handle /content/<basefolder>/<language>/<pagecategorytype>/(.*) /firstslash/$2/$2.html early


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.