Enable dispatcher caching for flat structured URL

 

We had an interesting problem to solve with in 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 which will vary from page to page. We have to enable caching for this URL in dispatcher and any update to one of the page 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

[code language=”css”]

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

[/code]

Our vanity url structure

[code language=”css”]

/firstslash/abcxxxxx

[/code]

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)

Network Diagram(1)

We had applied 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 second (from base) sub folder. Below is the entry to be updated

[code language=”css”]

statfileslevel "2"

[/code]

2) Configure your publisher’s apache to be requested for any customer request from dispatcher in your dispatcher.any file under “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.

[code language=”css”]

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

[/code]

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

[code language=”css”]

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

[/code]

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

Pub_invlidatecache

6) Now as a last step, we have to invalidate the cache only for the specific page based on activiation. 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)

[code language=”css”]

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

[/code]

Leave a Reply

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