开箱即用的缓存控制标头过滤器就可以了吗? [英] Right out of the box cache-control header filter?
问题描述
框高速缓存控制响应标头过滤器是否存在权限,该过滤器使我能够在我的静态资源上设置那些高速缓存标头,而无需构建自己的过滤器?这似乎是一项常见的任务.有弹簧过滤器吗?我目前正在使用Tomcat 6.0,并使用Spring的ShallowEtagHeaderFilter将etag设置为我的资源,但是我还需要添加缓存控制标头.
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.
推荐答案
将mvc:resources用于静态文件,将mvc:interceptor与WebContentInterceptor一起用于非静态文件,例如
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>
这篇关于开箱即用的缓存控制标头过滤器就可以了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!