Cache processes

  • Each time the browser initiates a request, it first looks up the result of the request and the cache identifier in the browser cache
  • Each time the browser receives the result of the returned request, it stores the result and the cache id in the browser cache

Strong caching procedure

When the browser sends a request to the server for the first time, the server returns the Cache rule in the HTTP header of the HTTP response packet together with the request result to the browser. The fields for controlling the mandatory Cache are Expires and cache-Control. Cache-control has a higher priority than Expires.

Expire, which is an HTTP1.0 field, is currently primarily used with http1.1’s cache-control

With HTTP/1.1, Expire was replaced by cache-control. The reason is that Expires caching works by comparing the client time with the time returned by the server. If either the client or the server has an incorrect time), the forced cache will be invalidated, so the existence of the forced cache will be meaningless.

The cache-control rules

In HTTP/1.1, cache-control is the most important rule, which is mainly used to Control web caching. Its main values are:

  • Public: All content will be cached (both client and proxy can be cached)
  • Private: All content can be cached only by the client. The default value of cache-control
  • No-cache: indicates the contents of the client cache, but whether to use the cache is verified by the negotiated cache
  • No-store: All content is not cached, that is, neither mandatory cache nor negotiated cache is used
  • Max-age = XXX (XXX is numeric) : The cache contents will expire after XXX seconds

Memory cache and hard disk cache

  • From memory cache: The memory cache has two characteristics, namely fast access and timeliness:

Fast read: The memory cache directly stores the compiled and parsed files into the memory of the process, occupying certain memory resources of the process, and facilitating the fast read of the next run.

Timeliness: Once the process is shut down, its memory is emptied.

  • From disk cache: The cache is directly written to the disk file. To read the cache, I/O operations are performed on the disk file stored in the cache and the cache content is parsed again. The reading of the cache is complex and slower than that of the memory cache