HTTP protocol Cache controlFirst request when the second request 304 not modified to modify the state
Explanation: There are some cache servers on the network, and the browser itself has caching capabilities. When we first visited a picture, the normal download of the image returned to the OK based on a premise-the image will not be changed frequently, the server returned 200, the image of the "signature"-ETag (the signature can be understood as the "fingerprint" of the image) when the browser again to access the picture, the server check "Fingerprint" If the picture does not change, directly using the picture in the cache, which reduces the burden on the server
grasping packet observation:
first time Request:
First Response header: The requested picture information can be seen in the response headeretag: "321397979879-fndlsh32yfsh894392"Last-modified:tue, June 2018 12:12:12 GMT
Second request header:inside the second request header:If-modified-since:tue, June 2018 12:12:12 GMTIf the picture has not been modified since Tue, June 2018 12:12:12 GMT, it will not be re-requested and will be re-requested if there is any modification .if-none-match: "321397979879-fndlsh32yfsh894392"if the current etag value of the picture does not match the value of the If-none-match, re-request
Second response header:Status Code 304 not modifiedif it's 304, you think the browser takes data from the local cache, saving the time it takes to transfer the image over the network .
Cache for large sites:if the site is larger and has n cache servers, how does the n cache server handle files on the master server? do you want to cache? How long does it take to cache the cache? there should be a protocol between the cache server and the primary server to illustrate these 2 issues
What protocols are used to illustrate these two issues?
Answer: or HTTP protocol, with the header information, Cache-control to control
using Protocol control cache (Apache server):using protocol to control caching:
related modules are---mod_expires expiresactive onexpiresbytype image/jpeg ' Access plus 1 month 'controls whether cache and cache cycles
in. htaccess, the specific syntax is as follows:ExpiresDefault "<base> [plus] {<num> <type>}*"expiresbytype type/encoding "<base> [plus] {<num> <type>}*"ExpiresDefault is to set the default cache parametersExpiresbytype is designed to design unique cache parameters by file typeWe use the second Test to set the one-month life cycle for JPG images .How do you understand the following 4 parameters? Base: Calculates the cache validity period based on which point of time Access/now: Based on the moment of the request response, such as from this moment to one months modification: calculated based on the last modified date of the requested file, such as the week after the last modification date remains in effect
Num: Cache time Size (in) Type: Cache time in units (days) instance: If this is the case in a clustered environment, the cache server will be considered effective within one months, thus reducing the burden on the primary server
use protocol to cancel cache (Apache server):
If some information is not cached, you have to go to the master server to get it. Client:Cache-control:no-cache pragma:no-cache
server-side Clear cache:
The relevant module is: Mod_header <filematch "\. (jpg|gif|png) $ ">Cache-control:no-cacheHeader unset EtagHeader unset last-modified</FilesMatch>
revalidate: To make a re-entry into force so as to have a new legal effect
refresh the browser request effect multiple times GIF will always request, JPEG will have a cache
Caching of HTTP protocols