Cache

Cache control of servers

  1. The browser discovers that there is no data in the cache, so it sends a request to obtain resources from the server;
  2. The server responds to requests, returns resources, and marks the validity period of the resources;
  3. Browser cache resources, waiting for next reuse.

Client cache control

  1. Caching is an important means of optimizing system performance, and it can be present at every stage of HTTP transmission;
  2. The server uses “Cache Control” to set cache policies, commonly known as “max age”, which represents the validity period of resources;
  3. When the browser receives data, it will be stored in the cache. If it has not expired, it can be used directly. If it has expired, it needs to go to the server to verify whether it is still available;
  4. To verify whether resources are invalid, a “conditional request” is required, commonly used are “if Modified Since” and “If None Match”. Upon receiving 304, the resources in the cache can be reused;
  5. There are two conditions for verifying whether a resource has been modified: “Last modified” and “ETag”, which need to be set by the server in the response message in advance and used in conjunction with conditional requests;
  6. The browser can also send the “Cache Control” field and refresh the data using “max age=0” or “no_cache”