当前位置:网站首页>HTTP cache - HTTP authoritative guide Chapter VII
HTTP cache - HTTP authoritative guide Chapter VII
2022-04-23 19:15:00 【Li Siwei】
WEB Caching can automatically save copies of common documents HTTP equipment .
- Reduce redundant data transmission : Saves network costs . When there is no cache , Same request , The server generates a document every time .
After there is a cache server , Generate documents only on the first request , And cache the document on the cache server , Subsequent requests are obtained directly from the cache server . The redundant transmission of network data of the original server is reduced . - Alleviate the network bottleneck problem : The request is partially distributed to the cache server , Original server
- Instant congestion : When a large number of users access the original server at the same time , Cause instant congestion . And after caching , Only the first request requires access to the original service area , Subsequent requests can be provided by the cache server , Solve the congestion problem .
- Distance delay : Requests can be routed to the nearest cache server , Instead of the original server far away , Reduce the network delay caused by geographical location .
hit 、 Not hit
If a copy of the requested resource already exists on the cache server , Cache hit .
If the requested resource does not have a copy on the cache server , Cache miss .
HTTP Revalidation 、 Freshness test
The cache should keep the copy the latest updated resource .
- If-Modified-Since: The cache server will initiate a request for a resource at the client 、 And the copy is old enough to need to be verified again , A revalidation message will be sent to the original server , ... will be added to the message if-modified-since This Header, With GET Command send ,
- 304 Reverify hit : If the server receives the revalidation message , It is found that the resource has not been updated compared to the cached copy , The response 304, It's called revalidation hit .304 In the response message , The data object is not obtained from the server , So it's a little faster than requesting the original server directly .
- Re verify misses : The resource has been updated , The server will respond to a 200 OK Message of , And send the latest data object to the cache server .
- 404 The object has been deleted : The resource has been deleted on the server , Then the server responds 404 To the cache server . The cache server is connected to 404 Delete its copy .
cache hit rate 40% reasonable
The proportion of the number of requests responded by the cache to the total number of requests .
Improving the cache hit rate is beneficial to reducing the network delay .
Byte hit rate
Due to different sizes of requested resources , Some size objects may be accessed less often , But due to size , It contributes more to the whole data flow
Improving the byte hit rate is beneficial to saving bandwidth .
How does the client distinguish whether the response is from the cache or the original server
- via: Some commercial agents will be in via Add some additional information to , To describe the cache hit
- Date: The client can send the... In the response header Date Compare with the current time , If Date The time is much earlier than the current time , You can think of it as a cache .
- Age:
Freshness test
- How to confirm whether freshness test is needed ?
cache-control : maxAge=1234455
Date : 2019 01 01 23:59:59
Date Is the first request , The creation time of the response message generated by the server ,maxAge Is the survival time of the copy .
If the current time is greater than Date+maxAge, Then the copy has expired , Freshness test is required
Expires : 2019 03 01 23:59:59
If the current time is greater than Expires, Then the copy has expired , Freshness test is required
- How to test freshness ?
last-modified: 2019 03 01 23:59:59 # HTTP Response head
if-modified-since : 2019 03 01 23:59:59 # HTTP Request header
The cache server will HTTP Respond to... In the copy last-modified The value of is used as the... In the request message if-modified-since value .
Send to the original server with if-modified-since Of header Message of , The server matches this time with the time of the latest resource last-modified Comparison .
if-modified-since The value of should be taken as... In the original copy last-modified Value .
Etag:“v4.6”,“v4.7” # Http Response head , The original server sends... To the cache
If-none-Match:“v4.6”,“v4.7” # http Request header , The cache sends a message to the original server
The cache server will the response headers in the replica Etag As a condition , Send to
-
How the original server responds to the freshness detection request of the cache server ?
304 not modified: If the cache content is still up to date , Then... Will not be sent in the response message body data , However, the cache server will update the response header in the copy according to the response header , Include last-modified、Date、cache-control:maxAge、Expires、Etag etc.
200 OK: If the copy of the cache server has expired , Then the original server will respond the new resource content to the cache . The cache server will take the response message as a new copy , Replace the original copy .
404: If the original server has deleted this resource , Then the cache will also delete the resource copy . -
Cache-control Meaning in response header
no-store: The original server tells the cache server , This response message should not be copied
no-cache: The original server tells the cache server , This response message can be cached , But every time a client requests this resource , Freshness verification is required
must-realidate:
max-age=123456: s-maxage=123456( Only for shared cache )
Expires: -
cache-control Meaning in request header
no-store: The client tells the cache , All documents for this resource should be deleted from the cache as soon as possible , Because it may contain sensitive information . Tell cache , Do not cache a copy of this resource
no-cache: The client tells the cache server , The freshness of resources must be verified , Then respond with the latest copy
max-age=123445: The client tells the cache , It is not allowed to return data that has been cached for more than max-age Copy of , If the cache time of the copy has exceeded the given max-age, Get the latest copy from the original server , Re response
min-fresh=12333: The client tells the cache , If the expiration time from the copy does not exceed min-fresh, You must get the latest copy from the original server , Respond to the latest copy to the client
only-if-cache: The client tells the cache , Only if a copy exists in the cache , The client will get a copy
版权声明
本文为[Li Siwei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210600381066.html
边栏推荐
- 剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
- [advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
- 优先使用组合而不使用继承
- MySQL restores or rolls back data through binlog
- Gossip: on greed
- PostgreSQL
- 浅谈c语言指针的强制转换
- SQL Server database in clause and exists clause conversion
- openlayers 5.0 当地图容器大小改变时,重新加载地图
- js上传文件时控制文件类型和大小
猜你喜欢
Getting started with vcpkg
Android Development: the client obtains the latest value in the database in real time and displays it on the interface
优先使用组合而不使用继承
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
[报告] Microsoft :Application of deep learning methods in speech enhancement
mysql_linux版本的下載及安裝詳解
ArcMap publishing slicing service
[advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
The platinum library cannot search the debug process records of some projection devices
ArcMap connecting ArcGIS Server
随机推荐
【历史上的今天】4 月 23 日:YouTube 上传第一个视频;网易云音乐正式上线;数字音频播放器的发明者出生
MySQL restores or rolls back data through binlog
PostgreSQL
Tencent cloud GPU best practices - remote development training using jupyter pycharm
Redis common interview questions
Customize the non slidable viewpage and how to use it
Common SQL commands
Codeforces Round #784 (Div. 4)
Parsing headless jsonarray arrays
Speculation on the way to realize the smooth drag preview of video editing software
优先使用组合而不使用继承
腾讯云GPU最佳实践-使用jupyter pycharm远程开发训练
arcgis js api dojoConfig配置
std::stoi stol stoul stoll stof stod
Esp01s with Arduino development environment
White screen processing method of fulter startup page
Codeforces Round #784 (Div. 4)
Reflection on the performance of some OpenGL operations in the past
The flyer realizes page Jump through routing routes
How to uninstall easyton