Cache role
-
Caching can reduce redundant code data transmission and save network costs
-
Alleviate network bottlenecks. You don’t need more width to load the page
-
Lower the original server request. The server can respond faster and avoid overloads
-
Reduce distance delay. Summary: Improved optimization from network cost, broadband, overload, distance.
Redundant code
It can be stressful to have many clients requesting the same resource at the same time and the server sending the same thing over and over again, but if you cache it, you keep a copy. This reduces replay traffic.
Bandwidth bottleneck
Broadband bottlenecks. Many networks provide broadband to local network clients that is wider than the original vehicle’s server. The client will access the server with the slowest path, which is the smallest bottleneck.
The distance problem
In my hometown, it may take tens of seconds to download a 5MB inventory file from a Server in Shanghai, but if you cache it, the next access will only take a few seconds. Local Ethernet is awesome. The longer the distance, the longer the delay of broadband transmission.
The instant congestion
Most of the time because of breaking news, videos, hot news, a lot of people accessing the document at the same time, it can get jammed instantly. At the peak of this peak, the server may crash directly. For example, when the Clinton investigation was being investigated, the server was receiving over three million requests per hour, 50 times its average. It’s like this car jam. It bothers me. I can’t move.
Cache hits and misses
The cache cannot hold a copy of every file in the world. If an existing copy can be used to reach the cache request service, this is called a cache hit. On the contrary, if no copy is available and then forwarded to the original server, this is called a cache miss.
In the validation
The original server content may be updated and changed, so the cache should be checked from time to time. For efficient validation, HTTP defines special requests that quickly check if the object is up to date without getting the full object from the server. A request is sent to the original service during the cache-on-cache copy validation, and if the contents have not changed, the server returns a 304 indicating that the copy is still valid. It’s still faster to validate a hit than a direct miss.
A tool that validates cached objects
HTTP if-modified-since header. Adding this header to get tells the server to return the object to the client if the content is updated.
- The server information is not modified. 304 The server information is not modified
- Server content modified 200 to modify and send the full content update cache copy
- Server resources to delete Delete 404 cache copy to delete
shooting
Cache hit ratio is the cache ratio, 40% hit ratio is reasonable.
Byte hit ratio
This criterion is that data is a good indicator of a service’s cache performance
Cache personal and share
- Personal professional caches are called private caches. Private caches don’t require much storage space. Browsers have built-in caches, or PC disk memory.
- The community caches shared by thousands of users are called shared caches, and the shared ones are called cache proxy servers or proxy caches.
The hierarchy of proxy caching
The idea is to use small, cheap caches closer to the client, and at a higher level, more powerful caches closer to the server for more shared documents. So if the URL request process may go through several levels of cache lookup. If level 1 does not hit the cache, a level 2 lookup might. And so on. This hierarchy has both advantages and disadvantages, because if you have too much hierarchy, then maybe every time you look for information, if there’s a hit file at the last level, that’s bad, and if there’s no hit file at all, that’s worse.
Mesh caching, content routing, and peer caching
Mesh cache is more complex than hierarchical cache, the bottom half of the writing, brain is a bit tired.
Procedure for handling the cache
- Receive – Cache reads incoming request packets from the network.
- Parsing – Parsing the heat preservation, extracting urls and various headers
- Query – Queries whether a local copy is available, and if so, obtains a copy
- Freshness detection – Check whether the cache is fresh if not nine updates
- Create a want-cache to build a response message with the new header and the cached body.
- Send – Play to the client through the network response
- Log – Create a log folder to describe this transaction
- Receive In the first step, the cache detects activity on a network connection and reads the input data. High-performance caches read data from multiple input connections at the same time and start processing transactions before the entire message arrives.
- The parse cache parses the request message into fragments, putting the various parts of the header into an easy-to-manipulate data structure. This makes it easier for the caching software to process the header fields and modify them. The parser is also responsible for standardizing the header sections, treating less important differences like case or replaceable data formats as equivalents. Also, some request messages contain complete absolute urls, while others contain relative urls and Host headers, so parsers often hide these details.
- The query cache retrieves the URL and looks for a local copy. A local copy may be stored in memory, on a local disk, or even on another nearby computer. Professional caches use fast algorithms to determine whether an object is in the local cache. If the document is not available locally, it can either fetch it from the original server or the parent agent, or return an error message, depending on the situation and configuration. The cached object contains both the server response body and the original server response header, so that the correct server header is returned in case of a cache hit. The cached object also contains metadata that records how long the object has been in the cache and how many times it has been used. Complex caches also retain a copy of the original client response header that triggered the server response for HTTP/1.1 content negotiation.
- Freshness detection HTTP retains a copy of a server document through caching for a period of time. During this time, the document is considered “fresh” and can be served by the cache without contacting the server. Once a cached copy stays too long beyond the freshness limit of the document, the object is considered “out of date” and the cache verifies with the server again to see if the document has changed before serving it. To make things even more complicated, all request headers sent by the client to the cache can themselves force the cache to revalidate, or avoid validation altogether. HTTP has a very complex set of freshness detection rules, compounded by the large number of configuration options supported by caching products and the need to interact with non-HTTP freshness standards.
- Creating a response We want the cached response to look like it came from the original server, and the cache takes the cached server response head as the starting point of the response head. The cache then modifies and extends these base headers to match the requirements of the client. For example, the server may return an HTTP/1.0 response (or even an HTTP/0.9 response) while the client expects an HTTP/1.1 response, in which case the cache must translate the header accordingly. Caches also insert freshness information into them (cache-Control, Age, and Expires headers), and often include a Via header indicating that the request was provided by a proxy Cache. Note: Cache should not adjust the Date header. The Date header represents the Date on which the object was originally generated by the original server.
- Send Once the response header is ready, the cache sends the response back to the client. Like all proxy servers, proxy caches manage connections to clients. High-performance caches try to send data as efficiently as possible and generally avoid copying document content between the local cache and the network I/O buffer.
- Logging Most caches hold log files and some statistics related to the use of the cache. After each cache transaction, the cache updates statistics on the number of cache hits and misses (as well as other relevant metrics) and inserts the entry into a log file that shows the request type, URL, and event that occurred. The most common cache log formats are Squid and Netscape’s extensible Common log format, but many caching products allow users to create custom log files.
- Cache processing flow chart
In simplified form, this shows how the cache handles requests to GET a URL:
Reference: HTTP authority guide, in line with the purpose of learning to record down, sometimes write these is also forced to often be asked, and their memory is very poor, a lot of time really can’t remember, in line with later can turn over the idea of recording down.