当前位置:网站首页>Node cache vs browser cache

Node cache vs browser cache

2022-06-24 12:32:00 mengmye

background :

CDN Node caching policy :

A reasonable caching policy can be set according to the actual business scenario , For example, follow the origin 、 follow CDN Configured cache time, etc , For different files , Or directory, etc . In cache time ,CDN The node directly caches the response to the client ; If cache expires , User access will trigger the node to go back to the source to verify whether the file is updated . If the file cache has not expired , But the origin site has been updated and wants users to access the new file immediately , The refresh operation can be submitted , Force clear CDN cache , Trigger the pull back to the source .

Browser caching strategy :

Mandatory cache : When the browser makes a request to the server , The server will put the caching rules into HTTP In response to a message HTTP The header is returned to the browser along with the request result , The fields that control the forced cache are Expires and Cache-Control, among Cache-Control Priority ratio Expires high .

Negotiate the cache : After the forced cache expires , The browser makes a request to the server with the cache id , Generally used if-modified-since/Last-Modified and if-none-match/Etag It is up to the server to decide whether the resources cached by the browser can be used .

In general , Node cache and browser cache are independent , It doesn't affect each other . But Tencent cloud in a specific scenario of a specific platform , The two will be related .

Problem description :

Customer feedback will be domain name vodtest.xiaobli.xyz “ All files are not cached ” After the policy of is deleted , Visit below url file ,CDN Nodes and browsers will cache , Fall short of expectations .

https://vodtest.xiaobli.xyz/nbi/rt/traffic/overview?platform=2&today=2021-03-18

Cause analysis :

1、 Confirm domain name vodtest.xiaobli.xyz Node caching policy for .

As shown below , Customer feedback url No match to any of the rules .

Test verification , Reproduce the phenomenon of caching in the node (Hit From Disktank3 That means cache hit ). And from the response header, you can find :

(1) When node cache misses , nothing Cache-Control: max-age Head ;

(2) When the node cache hits , Yes Cache-Control: max-age Head .

(3) Bind origin test , Source station none Cache-Control Related cache headers .

why CDN The node caches the file ? With this question , Search product documents (https://cloud.tencent.com/document/product/228/47672), Find the answer as follows :

Platform default policy

If you do not configure any rules, or if a request misses a configured rule , The following platform policies are followed by default :

  • When a user requests a business resource , If the source station corresponds to HTTP Response Header in Cache-Control Field , Follow this Cache-Control
  • If the source station corresponds to HTTP Response Header No middle Cache-Control Field , be :CDN The node caches the resource by default 600s.

Customer feedback url, Missed configured rules , And the source station has no Cache-Control Field , be CDN Nodes cache 600s.

2、 Confirm domain name vodtest.xiaobli.xyz Browser caching policy .

As shown below , The domain name has no browser cache expiration configuration . In this case , How long the browser caches depends on when accessing a resource , The server responds Cache-Control

or Expires. In general, this is 2 All headers are inherited from the source site ,CDN The side is not modified . Customer feedback on this url, The origin station does not have this 2 A head , It should not cache . But because of this file CDN After node caching , Will default to add Cache-Control: max-age=600, That causes the browser to cache .

Solution :

In addition to the file types for which the caching policy is explicitly set , No other files need to be cached , The following scheme can be adopted ( One out of two ).

1、 Based on the current cache policy , Add a new one “ All files are not cached ”( The lowest priority ) The bottom line strategy , Just operate the console .

2、 in the light of CDN There is no file type with explicit cache policy set on the side , The origin station needs to return Cache-Control:no-cache And so on .

原网站

版权声明
本文为[mengmye]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/06/20210601180749267u.html