rest - 显式禁用 REST 服务的缓存

标签 rest http-caching

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

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

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

    最佳答案

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

    HTTP caching specification Section 3禁止缓存响应时列出。它表明只要响应代码是可缓存的,就可以缓存响应。可缓存的响应代码列表在 HTTP specification section 6.1 中:

    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 caching specification section 4.2. )

    关于rest - 显式禁用 REST 服务的缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39129932/

    相关文章:

    http - 缓存控制 : 'private' makes 'no-cache="set-cookie"' unnecessary?

    caching - Etags 和 last-modified 通过 https SSL?

    reload - "Empty Cache and Hard Reload"是清空整个缓存还是仅清空与当前站点相关的部分?

    scala - Spark Send DataFrame 作为 HTTP Post 请求的主体

    javascript - 如何在 react 路由器中加载下一页之前等到服务调用完成

    REST 最佳实践云

    android - 调用 Sinch REST API 时出现 400 错误

    rest - 业务异常导致错误响应的http状态。语法正确,请求有意义

    tomcat - 页面未在浏览器中缓存

    node.js - 相当于 node.js 中的 .net 输出缓存?