Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

Custom cache control headers for specific pages

Avatar

Level 2

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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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:

  1. 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.

  2. 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>
  3. 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.

  4. 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.

  5. Validation
    After deploying, test using curl -I or tools like WebPageTest to see if the right headers are coming through Akamai.


Santosh Sai

AEM BlogsLinkedIn


View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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:

  1. 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.

  2. 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>
  3. 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.

  4. 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.

  5. Validation
    After deploying, test using curl -I or tools like WebPageTest to see if the right headers are coming through Akamai.


Santosh Sai

AEM BlogsLinkedIn


Avatar

Community Advisor

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.

 

 

Arun Patidar

AEM LinksLinkedIn

Avatar

Level 6

@AnujaRa Use the Apache's LocationMatch directive and set the TTL.

 

https://httpd.apache.org/docs/trunk/mod/core.html#locationmatch