Is there a right of the box cache-control response header filter that will enable me to set those cache headers on my static resources without me having to build my own Filter? It seems like such a common task. Is there a Spring filter ? I am currently using Tomcat 6.0 and using Spring's ShallowEtagHeaderFilter to set etag to my resources but I need to also add the cache-control headers.
Use mvc:resources for static files and mvc:interceptors with WebContentInterceptor for non-static files e.g.
<!-- cache for one month -->
<mvc:resources location="/css/" mapping="/css/**" cache-period="2592000"/>
<!-- don't send any cache headers, rely on last-modified timestamps only -->
<mvc:resources location="/img/" mapping="/img/**"/>
<mvc:resources location="/js/" mapping="/js/**"/>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**/*.htm" />
<bean id="responseCachingFilter" class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<property name="cacheSeconds" value="0" />
<property name="useExpiresHeader" value="true" />
<property name="useCacheControlHeader" value="true" />
<property name="useCacheControlNoStore" value="true" />
<property name="cacheMappings">
<props>
<!-- cache for one month -->
<prop key="/**/*.htm">2592000</prop>
</props>
</property>
</bean>
</mvc:interceptor>
</mvc:interceptors>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With