I have certain pages in my AEM site that need shorter TTL values due to frequent updates, while others can be cached longer. We are using AEM as a Cloud Service with Akamai as CDN and Dispatcher. What is the best way to handle this without breaking default caching behavior?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @AnujaRa,
So, IMO, the cleanest approach is to let the author control the cache behavior through a page property. For example, you can expose a dropdown in the page properties like cacheControl = short | long | no-cache, and based on that, you can set the appropriate headers.
From a technical angle, what we did was:
Expose a Custom Property
In your page component's dialog, expose something like cq:cacheControlType. Then you can read this in the HTL and set a custom header via a servlet or Sling model.
Update Apache/Dispatcher Rules
As per my understanding, Dispatcher can’t directly read JCR properties, so you’ll need to handle this in Apache. What we did was use URL patterns or markers in the URL (like /short-cache/) and then set headers:
<LocationMatch "^/content/mysite/.*short-cache.*">
Header set Cache-Control "max-age=300, public"
</LocationMatch>
Akamai Part
Make sure Akamai is not overriding these headers. Either ask your CDN team to allow origin headers or configure akamai.yaml to define behavior per path. Without this, Akamai might cache pages longer than you expect.
Optional: Use SDI for Partial Caching
If only a part of your page changes often (e.g., a news feed or stock ticker), Sling Dynamic Include is a great way to exclude that section from caching.
Validation
After deploying, test using curl -I or tools like WebPageTest to see if the right headers are coming through Akamai.
Hi @AnujaRa,
So, IMO, the cleanest approach is to let the author control the cache behavior through a page property. For example, you can expose a dropdown in the page properties like cacheControl = short | long | no-cache, and based on that, you can set the appropriate headers.
From a technical angle, what we did was:
Expose a Custom Property
In your page component's dialog, expose something like cq:cacheControlType. Then you can read this in the HTL and set a custom header via a servlet or Sling model.
Update Apache/Dispatcher Rules
As per my understanding, Dispatcher can’t directly read JCR properties, so you’ll need to handle this in Apache. What we did was use URL patterns or markers in the URL (like /short-cache/) and then set headers:
<LocationMatch "^/content/mysite/.*short-cache.*">
Header set Cache-Control "max-age=300, public"
</LocationMatch>
Akamai Part
Make sure Akamai is not overriding these headers. Either ask your CDN team to allow origin headers or configure akamai.yaml to define behavior per path. Without this, Akamai might cache pages longer than you expect.
Optional: Use SDI for Partial Caching
If only a part of your page changes often (e.g., a news feed or stock ticker), Sling Dynamic Include is a great way to exclude that section from caching.
Validation
After deploying, test using curl -I or tools like WebPageTest to see if the right headers are coming through Akamai.
Hi @AnujaRa
For dispatcher caching - https://medium.com/@angadi.saa/aem-how-dispatcher-4-3-5-balances-ttl-and-invalidation-for-optimal-fr...
For AKAMAI/Browser caching - Use dispatcher LocationMatch directive set cache-control header for those pages or use Sling Filter to set cache-control header from AEM.
@AnujaRa Use the Apache's LocationMatch directive and set the TTL.
https://httpd.apache.org/docs/trunk/mod/core.html#locationmatch
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies