I am using below code to add cache-control for static files.
public void setContentType(String type) {
if (type.startsWith("text/html") || type.endsWith("text/xml")) {
// For HTML and JSF files, no caching
super.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
super.setHeader("Pragma", "no-cache");
} else if (type.startsWith("text") || type.startsWith("image")) {
// For text and image files, cache for 8 hours
super.setDateHeader("Expires", System.currentTimeMillis() + EIGHT_HRS_IN_MILLIS);
super.setHeader("Cache-Control", "max-age=28800");
super.setHeader("Pragma", "public");
}
super.setContentType(type);
}
Initially it works fine and fetch from memory cache, but after some time it gives 304 error code and cache-control changes to no-cache. Which is causing slowness in loading the static content.
I tried with private window and localhost it works fine. When I deploy the code to jboss server the issue occurs, looks like no-cache is added from server end.
How to keep 8 hours cache-control and not to override by no-cache.