Search code examples
httpcachinghttp-headerscache-controlrequest-headers

How do caches validate the response when using `Cache-Control: no-cache`?


Quote from Cache-Control:

no-cache

The no-cache request directive asks caches to validate the response with the origin server before reuse.

Cache-Control: no-cache

no-cache allows clients to request the most up-to-date response even if the cache has a fresh response.

My understanding is that when using no-cache, the caches validate the response's time with the system time, if it's not the same, the clients will then request the latest response, is that correct?

If not, then how do caches validate the response when using Cache-Control: no-cache?


Solution

  • Thanks to Joe's comment, quoting from Hypertext Transfer Protocol (HTTP/1.1): Caching:

    Validation

    When a cache has one or more stored responses for a requested URI, but cannot serve any of them (e.g., because they are not fresh, or one cannot be selected; see Section 4.1), it can use the conditional request mechanism [RFC7232] in the forwarded request to give the next inbound server an opportunity to select a valid stored response to use, updating the stored metadata in the process, or to replace the stored response(s) with a new response. This process is known as "validating" or "revalidating" the stored response.