我试图让春天启动让浏览器缓存静态资源。 我的资源位于" static"下的类路径中。当我查看发回的标题时,我看到修改标题设置正常,但不知何故标题" Cache-Control:no-store"也加入了。
HTTP/1.1 200
Last-Modified: Wed, 24 Aug 2016 08:50:16 GMT
Cache-Control: no-store
Accept-Ranges: bytes
Content-Type: text/css
Content-Length: 434554
Date: Wed, 24 Aug 2016 09:42:42 GMT
我已经看到了这个答案How to enable HTTP response caching in Spring Boot,但这似乎并不适用于我,因为我没有使用spring-security,它不在类路径中。
我正在使用带有百里香的spring-boot 1.4.0。
那么,如何让spring boot不包含Cache-Control标头?
答案 0 :(得分:0)
至少在最近(2018年)的SpringBoot版本中,可以设置一些属性:
spring.resources.cache.cachecontrol.cache-private= # Indicate that the response message is intended for a single user and must not be stored by a shared cache.
spring.resources.cache.cachecontrol.cache-public= # Indicate that any cache may store the response.
spring.resources.cache.cachecontrol.max-age= # Maximum time the response should be cached, in seconds if no duration suffix is not specified.
spring.resources.cache.cachecontrol.must-revalidate= # Indicate that once it has become stale, a cache must not use the response without re-validating it with the server.
spring.resources.cache.cachecontrol.no-cache= # Indicate that the cached response can be reused only if re-validated with the server.
spring.resources.cache.cachecontrol.no-store= # Indicate to not cache the response in any case.
spring.resources.cache.cachecontrol.no-transform= # Indicate intermediaries (caches and others) that they should not transform the response content.
spring.resources.cache.cachecontrol.proxy-revalidate= # Same meaning as the "must-revalidate" directive, except that it does not apply to private caches.
spring.resources.cache.cachecontrol.s-max-age= # Maximum time the response should be cached by shared caches, in seconds if no duration suffix is not specified.
spring.resources.cache.cachecontrol.stale-if-error= # Maximum time the response may be used when errors are encountered, in seconds if no duration suffix is not specified.
spring.resources.cache.cachecontrol.stale-while-revalidate= # Maximum time the response can be served after it becomes stale, in seconds if no duration suffix is not specified.
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html