I wish to enable HTTP caching for some static resources such as images, for which access is restricted by Spring Security. (These resources are not security critical, but shouldn't be publicly accessible either). How do I avoid having Spring Security add HTTP response headers that disable caching?
If I add setCachePeriod()
into my resource handler registration in WebMvcConfigurerAdapter.addResourceHandlers()
as following:
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/").setCachePeriod(3600);
The resources are still returned with following headers that disable caching:
Cache-Control: max-age=3600, must-revalidate
Expires: Mon, 04 Aug 2014 07:45:36 GMT
Pragma: no-cache
I want to avoid introducing any XML configuration into the project, which currently uses only Java annotation configuration.
Are there better solutions than extending the Spring resource handler?