One: HTTP protocol cache control
The 1th time the request is OK
304 not Modified unmodified state on 2nd request
Explanation: There are some cache servers on the network, and the browser itself has caching capabilities.
When we first time a picture, normal download picture, return value 200
Based on the premise that the image does not change frequently, the server returns 200 and returns the "signature"-Etag of the image (the signature can understand the "fingerprint" of the image).
When browsing the picture again, go to the server to verify the "fingerprint",
If the picture does not change, use the image in the cache directly, which reduces the burden on the server.
Second: grasping the packet observation analysis
Three: HTTP protocol and cache control
If the site is larger, there are n cache servers, then this n cache server, how to handle the files on the master server,
1: Do you want to cache
2: How long is the cache?
Think----This illustrates that there should be some protocol between the cache server and the primary server to illustrate these 2 issues?
What agreements do----use to illustrate these 2 questions?
Answer-----or HTTP protocol, with the Cache-control of the header information to control
Specific usage:
On the master server, open Apache expires extension, use this extension to control pictures, css,html and other files
Controls whether the cache, and the cache life cycle.
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 parameters
Expiresbytype is designed to design unique cache parameters by file type
We use the 2nd type to do the test, the JPG image set 1 months of life cycle.
How do you understand the following 4 parameters?
Base: Calculates the cache validity period based on which point in time
Access/now: Based on the moment of request/response, for example from this moment to 1 months.
Modification: Calculated based on the last modified date of the requested file. For example, the last 1 weeks after the date of the modification will remain in effect.
Num: The size of the cache time (30)
Type: The unit of cache time (days)
Instance:
If this is in a clustered environment, the cache server gets this image and will be considered valid for one months.
Reduces the burden on the primary server.
Can we set up the server without caching?
For example, some personal information is not allowed cache server cache, must go to the master server to request.
Control-cache:no-store,must-revalidate; This means that caching is not allowed and must go to the primary server for authentication.
Can take advantage of Apache's header module
HTTP protocol Cache Control