Http protocol Cache
Http protocol Cache Control200 OK for the first request 304 not modified for the second request to change the status
Explanation: There are some cache servers on the network, and the browser also has the cache function. When we access an image for the first time, we can download the image normally and return the 200 OK message based on the premise that the image will not be changed frequently. When the server returns the 200 message, the "signature" -- etag (the signature can be understood as the "fingerprint" of the image) of the image is returned. When the browser accesses the image again, it checks the "fingerprint" on the server. If the image does not change, using cached images directly reduces the server load
Packet Capture observation: First request: First Response Header: In the response header, you can see the requested Image Information etag: "321397979879-fndlsh32yfsh894392" last-modified: Tue, 10 Jun 2018 12:12:12 GMT
The second request header:In the second request header: if-modified-since: Tue, 10 Jun 2018 12:12:12 GMT. if the image is not modified after the time of Tue, 10 Jun 2018 12:12:12 GMT, the request will not be sent again, if any modification is made, the request will be re-requested if-none-match: "3213979879-fndlsh32yfsh894392". if the latest etag value of the image does not match the value of if-none-match, the request will be re-submitted.
The second response header: status code 304 not modified. If it is 304, the browser retrieves data from the local cache, saving the image transmission time on the network.
Large website cache:If the website is large and there are N cache servers, how can these N cache servers process files on the master server? Do you want to cache? How long will the cache be cached? There should be some protocols between the cache server and the master server to illustrate these two problemsWhat protocols are used to illustrate these two problems? A:Or http protocol, with header information and cache-control to control
Use the protocol to control the cache (apache server ):Use protocol to control cache:The related modules are --- mod_expires.ExpiresActive On ExpiresByType image/jpeg 'Access plus 1 month'
In. in htaccess, the specific syntax is as follows: expiresDefault "<base> [plus] {<num> <type >}*" ExpiresByType/encoding "<base> [plus] {<num> <type >}*" ExpiresDefault yes. The default cache parameter ExpiresByType is designed according to the file type. We use the second method to test whether to set the four parameters after the one-month life cycle for JPG images. How can this problem be solved? Base: Based on the time point to calculate the cache validity period Access/now: the moment based on the request response, such as Modification from this moment to a month: calculated based on the last modification date of the requested file. For example, the last modification date is still valid within one week.
Num: cache time size (30) type: cache time unit (day) instance: if this is in the cluster environment, the cache server gets this image, will be considered valid for a month, thus reducing the burden on the master server
Cancel cache using protocol (apache server ): If some information is not cached and must be obtained from the master serverClient: Cache-Control: no-cache Pragma: no-cache
Server-side cache cleanup:Related modules: mod_header<FileMatch "\. (jpg | gif | png) $"> Cache-Control: no-cache Header unset Etag Header unset Last-Modified </FilesMatch>
Revalidate: Make it take effect again, make it legally effective from new