"HTTP authoritative guide" reading notes four

Source: Internet
Author: User

Cache


Re-authentication of the cache:

Because the files on the original server are subject to change at any time, the cache needs to be detected from moment to time, compared to whether the local cache is the same as on the original server, and this "freshness detection" is re-authentication.

Re-verify the frequency of the progress:

Most caches are only re-validated when the client initiates the request and the local cache copy is old enough to be detected.

When the cache is validated, a small validation request is sent to the server, and if the content does not change (that is, the cache is valid), the servers return a 304 not Modified.

Cache re-authentication tool: If-modified-since Header

When the if-modified-since header is added to a GET request, the server returns the object only if the copy of the object is cached, but the copy is modified.

Server content not modified: return 304 not Modified

Server Content modified: Returns the normal corresponding with HTTP OK

Server content deleted: return 404 Not Found


The date header for http: Dates after the time when the original server should request the first response.


Cache freshness Retention: Expires and Cache-control:max-age methods

Both expires and Cache-control:max-age set a time for the cache's validity period. The difference is that expires sets an absolute time, and cache-control:max-age sets a relative time in seconds.

Cases:

CACHE-CONTROL:MAX-AGE=3600 indicates that the server has failed to cache the document for 3,600 seconds from the first time a requested document was generated.

Expires:tue, 06:29:00 GMT means that the cache expires on May 5, 2015 6:29:00 (GMT, Beijing time Plus 8).

If the cached content exceeds the time set by the above method, it needs to be re-verified with the server.

Cache re-authentication requires two condition headers: if-modified-since: and If-none-match:

1. If-modified-since: If the document has been modified after the specified date, the request will be made to the server.

If the document is modified after the specified date, then the if-modified-since condition is true and a GET request is executed to get a new date.

If the document is not modified after the specified date, then the if-modified-since condition is false, and the server returns a 304 not Modified, which does not return the message body.

2. If-none-match: The server sets a special label (ETAG) for each document, and if the cached document label differs from the document's label on the server (not based on the modified time of the document), the If-none-match header executes the requested method.

If the client request header contains the If-none-match: "v1.0" condition, the server will contrast the ETag label "v1.0" behind If-none-match with the ETag label of the local document. If the same, the 304 not Modified is returned, and the response message contains: ETag: "v1.0", or if the ETag label is different, then a new ETag is returned.

If-none-match: You can include multiple ETag tags later.


"HTTP authoritative guide" reading notes four

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.