【发布时间】:2017-05-26 12:27:27
【问题描述】:
我正在尝试使用 spring boot 1.4.3 构建我的应用程序。我尝试将最大年龄设置为
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/css/**")
.addResourceLocations("classpath:/static/css/")
.setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS));
}
}
当我第一次访问我的页面时,我可以看到 Status=200 的响应标头,如
Accept-Ranges=bytes
Cache-Control=max-age=2592000
下次我第二次访问同一页面时,我可以看到 Status=304 但标题是 -
Cache-Control=no-cache, no-store, max-age=0, must-revalidate
Date=Wed, 11 Jan 2017 16:05:12 GMT
Expires=0
因此,当我第三次访问时,我所有的静态资源都是从服务器获取的,而不是缓存的。有人可以帮助我我缺少什么或做错了什么吗?提前致谢。
【问题讨论】: