Advantages and disadvantages of caching:

advantages

  1. Traffic saving broadband
  2. Reduce server requirements to avoid server overload
  3. Improves browser loading speed

disadvantages

  1. Consumes client memory

Mandatory cache

Request data is to cache the database to look up, there is to go to the data, there is no request to the server.

(Photo: juejin.cn/post/684490…) Strong caching is represented by the Expires and cache-Control fields in the request header

Expires

The Expires value is the data expiration time, and cached data is used when the request time is less than the Expires value.

Cache-control

Cache-control is used to distinguish between support for caching mechanisms and to provide different caching policies through the value of cache-control. No-store: all contents will not be cached. No-cache: data that needs to be authenticated. Private: the client can cache data

Negotiate the cache

The client will obtain the identification from the cache database, and verify whether the identification is invalid. If it does not take effect, 304 will be returned, and the client will obtain data from the cache database

Last-Modified

Last-modified: The server returns the last Modified time of the resource if-modified-since: the browser will carry the last Modified time when it requests it again. When a server receives a request and finds a request header with if-modified-since, it is compared with the last modification time of the resource. If so, 304 is returned. If not, if-unmodified0since: indicates whether the resource has been modified since a certain time. Returns 200 if no changes are made, and 412 if changes are made

Etag

If-none-match: when the browser makes a request again, the value of the last field will be the unique identifier (Etag) generated by the server. When the server receives the request, it will compare if-none-match. • Different: The resource has been modified and the new resource status is returned. 200 • Same: the resource has not been modified and 304 is returned. The browser cache the database to obtain data