Disable dispatcher caching for specific requests | Community
Skip to main content
Level 4
December 19, 2024
Solved

Disable dispatcher caching for specific requests

  • December 19, 2024
  • 2 replies
  • 1711 views

I have created a filter for asset requests to DAM. For certain assets, I want to completely disable caching in the dispatcher and AEMaaCS CDN.

 

Is it enough to simply set the headers from Java, or do I need to also apply some logic in the dispatcher?

 

For instance, I am doing something like this:

 

public static void removeResponseCaching(SlingHttpServletResponse response) { response.setHeader("Surrogate-Control", "no-store"); response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"); response.setHeader("Dispatcher", "no-cache"); response.setHeader("Pragma", "no-cache"); response.setHeader("Expires", "0"); }

 

However, I am noticing that cache control headers are still coming back for certain requests even though this code is being executed.

 

I am trying something like this in my vhost:

 

<LocationMatch "^/content/.*\.coreimg.*\.(?i:jpe?g|png|gif|svg)$"> <If "%{HTTP:Cache-Control} in { 'no-cache' }"> Header unset Cache-Control Header unset Expires Header set Expires 0 Header set Age 0 Header set Cache-Control "no-cache" Header set Surrogate-Control "private" </If> <Else> Header set Cache-Control "max-age=2592000,stale-while-revalidate=43200,stale-if-error=43200,public,immutable" "expr=%{REQUEST_STATUS} < 400" Header set Age 0 </Else> </LocationMatch>

 

If I make a request to the file and supply Cache-Control: no-cache on the request, then the response contains the proper Cache-Control: no-cache header.  However, if the request doesn't have the Cache-Control directive, it seems that the Cache-Control header is being set to 

Best answer by arunpatidar

Hi @dylanmccurry 

If you skip caching images, it will impact performance heavily. so reconsider caching again.

 

But in order to deny caching for dispatcher add a rule something like below : more info

 

/0005 { /glob "/content/.*.coreimg.*.(svg|pdf)" /type "deny" }

 

 
to disabled CDN cache add a cache-control header from vhost file , more info

 

<LocationMatch "^/content/.*\.(jpeg|jpg)$"> Header set Cache-Control "max-age=0" Header set Age 0 </LocationMatch>

 

2 replies

Kamal_Kishor
Community Advisor
Community Advisor
December 20, 2024

@dylanmccurry : If you don't want to cache certain requests based on their glob patterns, you should create a rule in your dispatcher configuration. Please refer: https://experienceleague.adobe.com/en/docs/experience-manager-learn/ams/dispatcher/understanding-cache#cache-filter-rules

 

Level 4
December 20, 2024

Can you create a glob pattern based on header values?

Kamal_Kishor
Community Advisor
Community Advisor
December 20, 2024

@dylanmccurry : glob pattern should be based on content (dam) path and not on header values.
You can refer other reply below from @arunpatidar and try with it for your use-case.

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
December 20, 2024

Hi @dylanmccurry 

If you skip caching images, it will impact performance heavily. so reconsider caching again.

 

But in order to deny caching for dispatcher add a rule something like below : more info

 

/0005 { /glob "/content/.*.coreimg.*.(svg|pdf)" /type "deny" }

 

 
to disabled CDN cache add a cache-control header from vhost file , more info

 

<LocationMatch "^/content/.*\.(jpeg|jpg)$"> Header set Cache-Control "max-age=0" Header set Age 0 </LocationMatch>

 

Arun Patidar