当前位置:网站首页>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
边栏推荐
- 2022.04.23(LC_763_划分字母区间)
- Openlayers 5.0 reload the map when the map container size changes
- Simple use of navigation in jetpack
- Openlayers 5.0 thermal diagram
- One stop service platform for high-level talents and development of comprehensive service platform system for talents
- Regular expressions for judging positive integers
- Audio signal processing and coding - 2.5.3 the discrete cosine transform
- 2022.04.23(LC_714_买卖股票的最佳时机含手续费)
- 【玩转Lighthouse】腾讯云轻量服务器搭建全平台视频解析视频下载网站
- 腾讯云GPU最佳实践-使用jupyter pycharm远程开发训练
猜你喜欢
ArcMap连接 arcgis server
Network protocol: SCTP flow control transmission protocol
Oracle configuration st_ geometry
Installation, use and problem summary of binlog2sql tool
An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
Class loading process of JVM
White screen processing method of fulter startup page
Getting started with vcpkg
Partage de la conception de l'alimentation électrique de commutation et illustration des compétences en conception de l'alimentation électrique
SQL常用的命令
随机推荐
Use of kotlin collaboration in the project
开关电源设计分享及电源设计技巧图解
The difference between ordinary inner class and static inner class
为何PostgreSQL即将超越SQL Server?
2022.04.23(LC_763_划分字母区间)
Oracle configuration st_ geometry
【玩转Lighthouse】腾讯云轻量服务器搭建全平台视频解析视频下载网站
Wechat applet part of the mobile phone Preview PDF did not respond
SSDB基础3
2022.04.23(LC_714_买卖股票的最佳时机含手续费)
Network protocol: SCTP flow control transmission protocol
[play with lighthouse] Tencent cloud lightweight server builds a full platform video analysis video download website
openlayers 5.0 两种居中方式
8266 obtain 18b20 temperature
Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
C1000k TCP connection upper limit test
SQL Server database in clause and exists clause conversion
One stop service platform for high-level talents and development of comprehensive service platform system for talents
The type initializer for ‘Gdip‘ threw an exception
JVM的类加载过程