显式禁用 REST 服务的缓存 [英] Explicitly disable caching for REST services

查看:70
本文介绍了显式禁用 REST 服务的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要将 Cache-Control: must-revalidate,no-cache,no-store 应用于来自后端 REST 服务的所有响应.我有两个问题:

I am to apply Cache-Control: must-revalidate,no-cache,no-store to all responses from out backend REST services. I have two questions about it:

  • 这样做很常见吗?出于某种原因,我认为这没有必要,但我(目前)还没有任何消息来源支持这一说法.
  • 我上面提到的值真的足够吗,还是应该设置更多?

发现这个:https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers#cache-prevention.是说浏览器可能会在没有明确配置时选择缓存,所以这意味着是的,如果我想确保缓存被禁用,应该配置它.

found this: https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers#cache-prevention. Is says browsers may choose to cache when nothing is explicitly configured, so it means yes, it should be configured if I want to make sure cache is disabled.

推荐答案

简短:是的,即使不存在显式控件,缓存也可能会缓存响应,您需要明确禁止它.

Short: yes, caches may cache the response even if no explicit controls are present, you need to explicitly disallow it.

HTTP 缓存规范第 3 节列出了何时禁止响应缓存.它表明响应可以被缓存,只要响应代码是可缓存的.可缓存响应代码列表位于 HTTP 规范第 6.1 节:

The HTTP caching specification Section 3 lists when the response is forbidden to be cached. It suggests that the response may be cached as long as the response code is cacheable. A list of cacheable response codes is in the HTTP specification section 6.1:

状态代码默认定义为可缓存的响应(例如,200、203、204、206、300、301、404、405、410、414 和 501此规范)可以被具有启发式的缓存重用除非方法定义另有说明,否则过期或显式缓存控制...

Responses with status codes that are defined as cacheable by default (e.g., 200, 203, 204, 206, 300, 301, 404, 405, 410, 414, and 501 in this specification) can be reused by a cache with heuristic expiration unless otherwise indicated by the method definition or explicit cache controls...

启发式过期"定义为不存在显式控件时分配的过期时间.(HTTP 缓存规范第 4.2 节.)

"Heuristic expiration" is defined as the expiration time assigned when no explicit controls are present. (HTTP caching specification section 4.2.)

这篇关于显式禁用 REST 服务的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆