Browsers are divided into negotiated caching and mandatory caching

Mandatory cache

Enforce caching headers. Use Expires in HTTP1.0. Use cache-control in HTTP1.1

Process: Initiates a request —- The browser determines whether the resource matches the “forcible Cache” based on Expires and cache-control —- if the resource matches, it will Cache the resource directly and does not request the server

Cache-control can be:

  • Public: All content is cached, as are clients and proxy servers
  • Private: All content is cached only by the client (this is the default for cache-control)
  • No-cache: indicates the content cached by the client, but whether to cache requires negotiation cache authentication
  • No-store: All content is not cached, neither mandatory nor negotiated
  • Max-age = XXX: the cache contents will be invalid in XXX seconds
  • Must-revalidate: Forces the browser to adhere to the cache rules you set
  • Proxy-revalidate: forces the proxy to adhere to the cache rules you set

Negotiate the cache

Force cache invalidity —- Trigger negotiation cache —- The client sends a request to the server with the negotiation cache id —- The server determines whether the cache id is valid

Two things happen

  • Negotiation cache takes effect, return 304
  • Negotiation cache invalid, returns 200 and result

Logic diagram for enforcement and negotiation