我已经在webapp的根目录中配置了Spring3MVC Dispatcher servlet,并使用mvc:resources提供静态内容,如文档:http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-static-resources中所述
谷歌的Chrome浏览器审计告诉我,这些资源显然是不可缓存的。下面是浏览器所说的与响应一起发送的报头:
Cache-Control:max-age=31556926, must-revalidate
Content-Length:1022
Content-Type:image/png
Date:Tue, 11 Jan 2011 00:20:07 GMT
Expires:Wed, 11 Jan 2012 06:08:53 GMT
Last-Modified:Mon, 29 Nov 2010 19:53:48 GMT那么,我需要什么才能使资源可缓存呢?
发布于 2015-06-01 05:09:37
在Spring Framework4.2中,this is now fixed with more flexible Cache-Control header values。
"must-revalidate"值现在默认情况下是禁用的,您甚至可以编写类似这样的代码:
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/static/")
.setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS).cachePublic());
}
}发布于 2012-10-12 04:06:24
也许org.springframework.web.servlet.mvc.WebContentInterceptor能帮到你?只需将其添加到拦截器列表中:
<mvc:interceptors>
<bean class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<property name="cacheMappings">
<props>
<prop key="/ajax/promoCodes">300</prop>
<prop key="/ajax/options">0</prop>
</props>
</property>
</bean>
</mvc:interceptors>https://stackoverflow.com/questions/4653122
复制相似问题