当前位置:网站首页>Specific process of strong cache and negotiation cache
Specific process of strong cache and negotiation cache
2022-07-28 11:51:00 【The king of the scroll goes to war】

When we first visit a page , We will get the static resource file of this page , Save it on local disk , This cache is called http cache ,http There are two types of caching , Strong cache and Negotiate the cache , Next, I will analyze these two in detail .
One 、 Judge the strong cache and negotiation cache
According to the diagram above , When browser page 2——>n The second time you visit this page , First, I will go to the local disk Determine whether it is a strong cache or a negotiation cache , According to the first request , Returned by the server expires and Cache-Control To judge ( The response header returned by the first request is also saved on disk , There are expires and Cache-Control Two fields of information ),expires and Cache-Control Specific fields :
expires yes http1.0 The specification of , There is the expiration time of the resource , As long as it is before the failure , This resource is always available .
expires:Mar, 06 Apr 2020 10:47:02 GMT.
Cache-Control: yes http1.1 What happened in , Generally, the max-age To judge , This value is a relative time .
Cache-Control:max-age=3600 // The period of validity of resources is 3600 second
In addition to this field, there are several other commonly used values .
no-cache: Do not use strong cache directly , Use the negotiation cache every time .
no-store: Direct disallow browser to cache data , Every time a user requests the resource , Will send a request to the server , Download full resources every time .
public: Can be cached by all users , Including end users and CDN Wait for intermediate proxy server .
private: Can only be cached by the end user's browser , Don't allow CDN Wait for the relay cache server to cache it .
Cache-Control Than expires Priority of
cache-control:max-age=691200
expires:Fri, 06 Mar 2020 10:47:02 GMT
So the maximum time that a resource can be cached is 691200 second , Will give priority to max-age.
Two 、 Negotiation cache continues to judge
The above judgment shows , If it doesn't expire , This is strong cache , After expiration , This must be the negotiation cache , Here are four attributes
Last-Modify If-Modify-Since
Etag If-None-Match
Last-Modify Is the first time you visit this page , The value returned by the server , We save it on local disk ( image expires and Cache-Control equally ), When we ask again ( It has been determined that the negotiation cache is not a strong cache ), Will be able to Last-Modify Copy the value of , Put it in the request header and send it to the server , At this time, the attribute name is changed to If-Modify-Since, in other words ,Last-Modify Only response headers exist ,If-Modify-Since Only request headers exist .
If-Modify-Since The value of is judged by the server ( The last time the server updates resources will be recorded , Compare these two times , If the update time be equal to If-Modify-Since Value ), return 304, The request body has no data , Front end access 304, Take the negotiation cache by yourself . If ( Server resource update time New to If-Modify-Since Value ), return 200 And the latest cached data .
From the above, you may feel that using Last-Modified Enough to let browsers know if the local cache copy is new enough , Why do we still need Etag Well ?
Some files on the server may change periodically , But his content doesn't change ( Just change the modification time ), At this time, we don't want the client to think that the file has been modified , And regain ;
Some files on the server are modified very frequently , For example, modify it in seconds or less , Still in this second , The content has changed , Time is still this time .
therefore Etag As a unique identifier , You can compare the cached content , Not just a comparison of time .
Last-Modified And ETag The effect is as like as two peas. , and ,Last-Modified And ETag It can be used together , Server will give priority to authentication ETag, Consistent case , Will continue to compare Last-Modified, Finally, I decide whether to return or not 304.
Again , there ETag and If-none-match That's what it means , The first time a browser requests a resource , obtain ETag Value , The browser assigns this value to If-none-match, Send to the server (ETag Only exists in the response header ,If-none-match Only exists in the request header ),
Return the corresponding status code and cache and above last-modify similar .
边栏推荐
- Jupiter、spyder、Anaconda Prompt 、navigator 快捷键消失的解决办法
- DNS series (III): how to avoid DNS spoofing
- Installing sqlmap on win10 (Windows 7)
- Design a system that supports millions of users
- Three methods of using unity mouse to drive objects
- How to effectively implement a rapid and reasonable safety evacuation system in hospitals
- Unity鼠标带动物体运动的三种方法
- [极客大挑战 2019]BabySQL-1|SQL注入
- Interfaces and abstract classes
- R language uses oneway The test function performs one-way ANOVA
猜你喜欢
![[pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?](/img/2b/1eb02249ab9ad0b4e1bfeeee87418c.png)
[pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?

Software testing and quality learning notes 1 --- black box testing

Techniques for visualizing large time series.

Will PFP be the future of digital collections?

Introduction to the usage of SAP ui5 image display control avatar trial version

Localization, low latency, green and low carbon: Alibaba cloud officially launched Fuzhou data center

Minikube initial experience environment construction

Outlook suddenly becomes very slow and too laggy. How to solve it

直接插入排序与希尔排序

STL の 概念及其应用
随机推荐
Will PFP be the future of digital collections?
consul安装与配置
Thinkphp5 behavior hook return result (data) example
Good use explosion! The idea version of postman has been released, and its functions are really powerful
P5472 [NOI2019] 斗主地(期望、数学)
PFP会是数字藏品的未来吗?
Installing sqlmap on win10 (Windows 7)
【补题日记】[2022牛客暑期多校2]H-Take the Elevator
我想请教下各位大佬,cdc采集mysql时,如果发生了主从切换,有什么方案可以处理吗
ZBrush 2022 software installation package download and installation tutorial
R language - some metrics for unbalanced data sets
MySQL (version 8.0.16) command and description
Introduction to web security RADIUS protocol application
108. Introduction to the usage of SAP ui5 image display control Avatar
R language uses dplyr package group_ By function and summarize function calculate the mean value of all covariates involved in the analysis based on grouped variables (difference in means of covariate
Cvpr2021 pedestrian re identification /person re identification paper + summary of open source code
In order to ensure the normal operation of fire-fighting equipment in large buildings, the power supply monitoring system of fire-fighting equipment plays a key role
R语言-用于非平衡数据集的一些度量指标
Byte side: how to realize reliable transmission with UDP?
301. Delete invalid brackets