Is Cache-Control:must-revalidate obliging to validate all requests, or just the stale ones?

后端 未结 1 644
Happy的楠姐
Happy的楠姐 2021-01-02 17:51

I have a mess with this header, I have read that Cache-Control:must-revalidate oblige to validate all requests with the source before serving a cached item, but

1条回答
  •  一整个雨季
    2021-01-02 18:18

    Section 14.9.4 of HTTP/1.1:

    When the must-revalidate directive is present in a response received by a cache, that cache MUST NOT use the entry after it becomes stale to respond to a subsequent request without first revalidating it with the origin server

    Section 14.8 of HTTP/1.1:

    If the response includes the "must-revalidate" cache-control directive, the cache MAY use that response in replying to a subsequent request. But if the response is stale, all caches MUST first revalidate it with the origin server...

    So it appears that only stale responses must be revalidated if must-revalidate is received.

    For no-cache, see section 14.9.1:

    If the no-cache directive does not specify a field-name [which is the case here], then a cache MUST NOT use the response to satisfy a subsequent request without successful revalidation with the origin server...

    Thus, no-cache applies both to fresh and stale responses.

    EDIT:

    This phrase may be relevant here (section 13.3):

    When a cache has a stale entry that it would like to use as a response to a client's request, it first has to check with the origin server (or possibly an intermediate cache with a fresh response) to see if its cached entry is still usable.

    So, must-revalidate is probably relevant when the cache has intermediate caches, since otherwise the cache can check the intermediate cache for a fresh response rather than check the origin server directly.

    0 讨论(0)
提交回复
热议问题