In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "what is the meaning of CDN cache". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
CDN is a service that accelerates website access and users download resources, so what does CDN caching mean? What are the advantages and disadvantages? In this regard, this article will tell you those things about CDN acceleration, interested partners remember to understand.
What is CDN?
About what CDN is, it has been introduced in detail for you before, and if there are any partners who do not understand it, you can re-understand it.
To put it simply, CDN is the abbreviation of Content Delivery Network, which means "content distribution network". Generally speaking, what we call CDN acceleration generally refers to the acceleration of websites or users' downloading resources.
Perhaps this kind of professional said, many friends are difficult to understand, the following to share with you an example of deep memory of the editor.
Take a popular example:
When it comes to the role of CDN, we can use the experience of buying train tickets for 8 years as an analogy: eight years ago, there was no train ticket agency, and there was no way to say 12306.cn. At that time, train tickets could only be bought in the ticket hall of the railway station, but the small county town where I lived did not have access to the train, so train tickets had to be bought at the railway station in the city, and it was a four-hour drive from the county to the city, which was a waste of life.
Later, there was a train ticket agency in a small county, where you can buy trains directly, which is much more convenient, and the people of the city no longer have to wait in a hard queue to buy tickets.
CDN can be understood as the train ticket sales outlets distributed in each county. When users browse the website, CDN will select the nearest CDN edge node to respond to users' requests, so that Hainan Mobile users' requests will not go all the way to the server in Beijing Telecom's computer room (assuming that the origin server is deployed in Beijing Telecom's computer room).
The advantages of CDN are obvious:
(1) the CDN node solves the problem of cross-operator and cross-regional access, and the access delay is greatly reduced.
(2) most of the requests are completed at the CDN edge node, and CDN acts as a diversion, reducing the load on the origin server.
What is the CDN cache?
This article does not delve into the high-end architecture behind CDN, nor does it discuss how CDN implements the global traffic scheduling strategy. This article focuses on how data is cached with CDN. Caching is a ubiquitous example of trading space for time. By using extra space, we can get faster speed.
Related skills: [how to see whether the website has opened the CDN test website national access speed method].
First, look at how the user's browser interacts with the server when there is no website without access to CDN:
When a user is browsing a website, the browser can save copies of pictures or other files in the site locally, so that when the user visits the site again, the browser does not have to download all the files. Reducing downloads means increasing the speed of page loading.
If you add a layer of CDN in the middle, the interaction between the user's browser and the server is as follows:
The client browser first checks whether the local cache expires. If it expires, it initiates a request to the CDN edge node. The CDN edge node detects whether the cache of the user's requested data expires. If it does not, it responds directly to the user's request, and a completed http request ends. If the data has expired, the CDN also needs to issue an origin-pull request (back to the source request) to the origin server to pull the latest data. A typical topology diagram for CDN is as follows:
As you can see, in the scenario where CDN exists, the data goes through two stages: client (browser) cache and CDN edge node cache. The caching of these two stages is analyzed in detail below.
Client (browser) cache
1) disadvantages of client caching
The client cache reduces the number of server requests, avoids repeated file loading, and significantly improves the user location. But when the site is updated (such as replacing css, js, and image files), the browser still saves the old version of the file locally, resulting in unpredictable consequences.
Once upon a time, when a page was loaded, the position of the elements on the page floated randomly, and the button clicked failed, and the front-end GG would habitually ask, "is the cache clear?" And then Ctrl+F5 Everything is OK. But sometimes, if we simply hit an enter in the browser address bar, or just press F5 to refresh, the problem is still not solved, do you know these three different operations, determine the browser's different refresh cache strategy?
How does the browser determine whether to use a local file or a new file on the server? Here are several methods of judgment.
Browser caching policy
Expires
Expires:Sat, 24 Jan 2015 20:30:54 GMT
If Expires is set in the http response message, we avoid connecting to the server before the Expires expires. At this point, the browser does not need to send a request to the browser, just need to judge whether the material in hand is out of date, and there is no need to increase the burden on the server at all.
Cache-control: max-age
Expires's method is good, but we have to calculate a precise time every time. Max-age tags make it easier for us to handle expiration times. All we have to say is that you can only use this information for a week.
Max-age is measured in seconds, such as:
Cache-Control:max-age=645672
Specify that the page expires after 645672 seconds.
Last-Modified
In order to notify the browser of the current version of the file, the server sends a label of when it was last modified, such as:
Last-Modified:Tue, 06 Jan 2015 08:26:32 GMT
In this way, the browser knows the creation time of the file he received, and in subsequent requests, the browser validates according to the following rules:
1. Browser: Hey, I need the jquery.min.js file. If you modified it after Tue, 06 Jan 2015 08:26:32 GMT, please send it to me.
two。 Server: (check file modification time)
3. Server: Hey, this file has not been modified since that time, you already have the latest version.
4. Browser: great, then I'll show it to the user.
In this case, the server only returns a 304 response header, which reduces the amount of data in the response and improves the speed of the response.
The following figure shows that after pressing F5 to refresh the page, the page returns a 304 response header.
ETag
In general, it is feasible to compare files by modification time. However, in some special cases, such as the server clock error, the server clock modified, and the server time not updated in time after the arrival of daylight saving time DST, all these will cause the problem of comparing file versions through modification time.
ETag can be used to solve this problem. ETag is the unique identifier of a file. Like a hash or fingerprint, each file has a separate logo, which changes as soon as the file changes.
The server returns an ETag tag:
ETag: "39001d-1762a-50bf790757e00"
The next visit order is as follows:
1. Browser: Hey, I need the file jquery.min.js. Is there anything that doesn't match the string "39001d-1762a-50bf790757e00"?
two。 Server: (check ETag … )
3. Server: Hey, my version here is also "39001d-1762a-50bf790757e00". You are already the latest version.
4. Browser: OK, then you can use the local cache
Like Last-modified, ETag solves the problem of file version comparison. It's just that ETag has a higher level than Last-Modified.
Extra label
Cache tags never stop working, but sometimes we need some control over what is already cached.
Cache-control: public indicates that the cached version can be recognized by a proxy server or other intermediate server.
Cache-control: private means that this file is different for different users. Only the user's own browser can cache, and the public proxy server does not allow caching.
Cache-control: no-cache means that the contents of the file should not be cached. This is very useful in search or page flipping results, because the corresponding content changes with the same URL.
Browser cache refresh
1. Enter the URL in the address bar and press enter or click the go button
The browser obtains the data of the web page with the least number of requests, and the browser directly uses the local cache for all the content that has not expired, thus reducing the request to the browser. Therefore, the Expires,max-age tag is only valid in this way.
two。 Press F5 or browser refresh button
The browser appends the necessary cache negotiation to the request, but does not allow the browser to use the local cache directly, which works for Last-Modified and ETag, but not for Expires.
3. Press Ctrl+F5 or Ctrl and click the Refresh button
This is a forced refresh, which always initiates a completely new request without using any cache.
CDN caching
When the browser local cache expires, the browser initiates a request to the CDN edge node. Similar to browser caching, CDN edge nodes also have a caching mechanism.
Disadvantages of CDN caching
The diversion function of CDN not only reduces the access delay of users, but also reduces the load of the origin server. But its disadvantage is also obvious: when the website is updated, if the data on the CDN node is not updated in time, even if the user uses Ctrl + F5 to invalidate the cache on the browser side, it will lead to abnormal user access because the CDN edge node does not synchronize the latest data.
CDN caching strategy
CDN edge node caching strategies vary with different service providers, but generally follow the http standard protocol, through the Cache-control: max-age field in the http response header to set the CDN edge node data cache time.
When the client requests data from the CDN node, the CDN node will determine whether the cached data has expired, and if the cached data has not expired, it will directly return the cached data to the client; otherwise, the CDN node will send a back-to-origin request to the origin server, pull the latest data from the origin server, update the local cache, and return the latest data to the client.
CDN service providers generally provide multiple dimensions based on file suffixes and directories to specify CDN cache time to provide users with more refined cache management.
CDN cache time has a direct impact on the "back-to-origin rate". If the CDN cache time is short, the data on the CDN edge nodes will often fail, resulting in frequent origin-pull, increasing the load on the origin server and increasing access latency; if the CDN cache time is too long, it will bring the problem of slow data update time. Developers need to add specific business to do specific data cache time management.
CDN cache refresh
CDN edge nodes are transparent to developers. Compared with the forced refresh of browser Ctrl+F5 to invalidate the browser local cache, developers can clean up the cache of CDN edge nodes through the "refresh cache" interface provided by CDN service providers. In this way, after updating the data, the developer can use the "refresh cache" function to force the data cache on the CDN node to expire, ensuring that the client pulls the latest data when accessing it.
That's all for "what does CDN caching mean?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.