Expand my Community achievements bar.

Disable dispatcher caching for specific requests

Avatar

Level 5

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 

0 Replies