Author’s brief introduction

Mr Lemon, senior operations engineer (self-described), SRE specialist (target), dreams of buying a Porsche by the age of 35. Like to study the bottom technology, think the bottom foundation is king. All new technologies are inseparable from the operating system (CPU, memory, disk), network, etc. Adhere to the input and output, record their own learning bit by bit, in the ordinary insist on moving forward, one day will meet a different yourself. Public account: Yunwewang (ID: Leeeee_Li).
                                                                 
                                                                                   
 

First, the advantages of caching

1. Reduce redundant data transmission

When multiple clients access a server, the server will transmit a document multiple times to one client at a time. Some of the same bytes are transferred over and over again in the network, and these redundant data transfers can consume network bandwidth, slow down transmission speed, and increase the load on the Web server. With caching, a copy of the first server response can be kept, and subsequent requests can be responded to by cached copies.
2. Alleviate network bottlenecks

Caching can alleviate network bottlenecks. Many networks provide more bandwidth for local network clients than remote servers. The client accesses the server at the slowest network speed on the path. If the client gets a copy from the cache on a fast LAN, the cache can improve performance, especially if the files being transferred are large.
3. Instant congestion

Cache plays an important role in breaking instantaneous congestion.
4. Distance delay

When bandwidth is not an issue, each router increases the latency of Internet traffic.
 

Cache hit

1. Cache hit

Existing replicas serve certain requests that reach the cache, called cache hits.
 
2. The cache fails to match

Some requests that reach the cache may be forwarded to the original server because no copy is available, which is called cache miss.
 

3. HTTP revalidation

The contents of the original server may change, and caches check to see if the copy they keep is still the most recent copy on the server, a freshness check known as HTTP revalidation.
 
3.1. Verify hit again
 
When the cache revalidates a cached copy, it sends a small re-authentication request to the original server. If the content has Not changed, the server returns 304 Not Modified. This authentication is called a revalidate hit or slow hit
 

 

3.2. Reverification failed
 
If the server object is different from the cache copy, the server returns 200 OK
 

 

3.3 The Object is Deleted
 
If the server object has been deleted, the server returns a 404 Not Found response, and the cache removes its copy.
4. Cache hit ratio

The percentage of requests that the cache serves is called the cache hit rate, also known as the document hit rate.
5. Byte hit ratio

The byte hit ratio represents the percentage of bytes supplied by the cache out of all bytes transferred.

3. Processing steps of cache

 

1. Receive: Caches incoming request packets received from the network.
2. Parsing — The cache parses the packet and extracts the URL and various headers.
3, query – cache to see if there is a local copy available, if not, go to the server to get a copy and save locally.
4. Freshness check – The cache checks to see if the cached copy is fresh, and if not, asks the server if there have been any updates.
5. Create response — The cache builds a response message from the new header and the cached body.
Send — The cache sends the response back to the client over the network.
7. Log – The cache optionally creates a log file entry describing the transaction.
 
 

Four, mark

1. Expiration response header

Cache-Control: max-Stale caches can optionally provide stale file caches- Control: Max - stale = < s > < s >Documents cannot expire the Cache in seconds-control: min-fresh=<s> At least for <s>Keep the document Cache fresh for seconds-control: max-age Specifies the maximum time for which the resource can be cached (kept fresh), Max -Age is the number of seconds Cache from the time when the request was initiatedNo - ControlEach time a cache is issued by a request, the cache sends the request to the server for re-authentication. If the request does not expire, the cache returns the local cache copy to the cacheNo - ControlThe store cache does not store any client or server response. A complete response Expires is downloaded every time a client initiates a request. An absolute expiration date is specified. Such as Wed,06 Jan 2021 09:35:39 GMT

 

 
Until cached documents expire, the cache can use these copies as often as it wants without contacting the server (except in special cases). Once a cached document expires, the cache must check with the server to see if the document has been modified, and if so, get a new copy (with a new expiration date).
 
2. Revalidation of conditional methods

If-modified-since:

Executes the requested method If the document has been Modified Since the specified date. Can be used in conjunction with the last-modifed server response header to retrieve content only if it has been modified to be different from the cached version.
 
If-none-match :

The server can provide a special ETag for the document instead of matching it to the most recently modified date. These labels act like serial numbers. If the cached label is different from the label in the server document. The if-none-match header executes the requested method.
 

🏆 technology project issue 8 chat | magical function and problems of cache