【问题标题】:How to set to disable browser cache in spring boot?如何在spring boot中设置禁用浏览器缓存?
【发布时间】:2019-07-11 11:29:13
【问题描述】:

我想在 spring boot 中设置禁用浏览器缓存(cache-control: no-cache, no-store, max-age=0)。

我的环境

  spring-boot: 2.1.2
  spring-security: not use

我搜索是否要设置响应头的缓存控制:无缓存, 只需在 'application.yml' 中添加即可。

喜欢这个

spring.resources.cache:
  cachecontrol:
    max-age: 0
    no-cache: true
    no-store: true
    cache-private: true

或

spring.resources.chain.cache: false

但它不起作用。

我无法在我的 chrome 浏览器的响应标头中显示缓存控制标头。

在spring-framework中,我只是设置

<mvc:mapping path="/**"/>
    <bean id="webContentInterceptor" 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"/>
    </bean>
</mvc:interceptor>

如何在没有spring security的情况下在spring boot中设置禁用浏览器缓存?

谢谢。

【问题讨论】:

    标签: spring spring-boot caching browser-cache


    【解决方案1】:

    尝试在 application.properties 中添加这一行

    spring.cache.type=NONE
    

    【讨论】:

    • 谢谢,但我添加了代码,它仍然响应标头不显示'cache-control'或'pragma'标头。
    猜你喜欢
    • 2016-12-31
    • 2012-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 2018-08-30
    相关资源
    最近更新 更多