HTTP protocol Cache Control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.