【问题标题】:spring boot cache control is not working properly. max age gets reset to 0spring boot 缓存控制无法正常工作。最大年龄重置为 0
【发布时间】: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

因此,当我第三次访问时,我所有的静态资源都是从服务器获取的,而不是缓存的。有人可以帮助我我缺少什么或做错了什么吗?提前致谢。

【问题讨论】:

    标签: spring-boot cache-control


    【解决方案1】:

    这可能是 Spring Security 的问题,其中缓存控制标头在控制器中被忽略,请检查 link 问题和解决方法 link

    此问题已在最新版本的 spring security (5.0.2) 中修复

    【讨论】:

      猜你喜欢
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多