当前位置:网站首页>HTTP cache < strong cache and negotiation cache >

HTTP cache < strong cache and negotiation cache >

2022-06-12 18:02:00 Out of the autistic bird

HTTP cache

HTTP The basic operation of caching

 Please add a picture description

  1. The browser checks whether it has a cache , If not, ask the server
  2. If the browser has , You need to check whether the cache has expired
  3. Use if it doesn't expire , Verify with the server when it expires
  4. The server tells you that you can continue to use it without expiration , The server tells you that it has expired to get a new one

in general : Browser first check , Let's see if the browser itself is expired , Then check with the server to see if it is expired

Strong cache

The server sends... Through the response header Catch-Control, Set the expiration time of the resource

1. public            These resources can be cached by any object ( Such as : client , proxy server , wait )
2. private           These resources can only be cached on the client 
3. max-age=xx        Set the maximum time for resource caching , Time out indicates that the cache has expired , The request is sent to the server ( Company : second )
4. no-cache          Before loading cache resources , Force a request to be sent to the server “ Negotiate the cache ”
5. no-store          Is not cached at all 

Negotiate the cache

The server returns the resource and resource ID , When the client sends a subsequent request , Send the request and resource ID to the server , If not the latest resources , Server return 200、 Latest resource and latest resource identification ; If it is the latest resource , Then the server returns 304, Get resources directly from the cache .

Resource identification :

  • Last-Modified: The time when the resource was last modified ( understand )
  • ETag: The resource corresponds to a unique string

ETag: Requests initiated on the client , The request header will carry if-none-match, The value is... Of the last response ETag, The server will ETag Contrast , Same back 304, Just get it from the local cache .

difference

The main difference between the two is : Strong caching does not make requests to the server , The negotiation cache will

原网站

版权声明
本文为[Out of the autistic bird]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206121758171115.html