"HTTP authoritative guide" reading notes-caching

Source: Internet
Author: User

Overview

The Web cache can automatically save HTTP devices for common document replicas. When a Web request arrives at the cache, the document is extracted from the local storage device instead of the original server if there is a locally cached copy.

Advantages of using caching

    1. Reduced redundant data transfer
    2. Alleviates network bottlenecks (no more bandwidth is allowed to load faster)
    3. Reduced requirements for the original server
    4. Reduction of distance delay
Redundant data transfer1. When multiple users access the original server page, the server transmits the same document multiple times, and the same bytes are transmitted over the network over and over again. With the cache, a copy of the first server response can be preserved, and subsequent requests can be handled by the cache's counterpart. 2. Because the cache is placed near the computer room, you can make the client get a copy faster. "hits and Misses"Cache Hit: You can use an existing replica to service certain requests that reach the cache. Cache misses (cached Miss): No replicas are available and are forwarded to the original server. Re-verify  the contents of the original server may change, and the cache will detect it at any time to see if the saved copy is up to date. "Freshness Detection" is known as HTTP re-authentication (revalidation). For effective validation, HTTP defines special requests and does not use the entire object from the server to quickly detect whether the content is up to date. since the cache typically contains millions of of documents, and the network bandwidth is precious, most caches are only validated when the client initiates the request and the copy is old enough to be detected. when the cache is re-authenticated against a cached copy, a small re-authentication request is sent to the server. If the cached copy is still valid, the copy is flagged as fresh and the copy is provided to the client, which is called the re-authentication hit (revalidate hits). It is usually verified with the if-modified-since header, which is added to the GET request and can be told to the server.
The following are three scenarios that may appear in the response message (the content is unmodified, the content is modified, and the content is deleted):
    • Re-verify Hit
If the server object is not modified, the server sends a small HTTP 304 not modified response to the client.
    • Re-authentication Misses
If the server object differs from the cached copy, the server sends a normal, full-content HTTP OK response to the client.
    • object is deleted
If the server object has been deleted, the server sends a 404 Not Found response, and the cache deletes its copy. Differentiate between hit and miss scenariosHTTP does not provide a means for users to differentiate whether a response is a cache hit or to access the original server. In both cases, the return is OK.the client has a way to determine whether the response is from the cache or to use the date header. The value of the date header in the response is compared to the current time, and if the date value in the response is earlier, the client is generally considered to be from the cache, and the client can also detect the cached response through the age header, which can be used to identify the lifetime of the response. Otherwise, it is assumed to be from the original server. Two cache typesPrivate cacheWeb browsers have built-in private caches, and most browsers cache common documents on your PC's disk and memory, and allow users to configure the size and settings of the cache. You can also see what's in the browser's cache. the private cache does not require much power or storage space. Public Proxy CacheThe public proxy cache is a special shared proxy server, known as a cache proxy server (caching proxy), or proxy cache. The proxy cache extracts the document from the local cache or contacts the server on behalf of the user. The public cache accepts access from multiple users, so it's better to reduce redundant traffic. process steps for cachingThe basic caching process for an HTTP GET message consists of 7 steps
    1. Accept-Caches a request message that reads the arrival from the network.
    2. Parse-The cache parses the message, extracting the URL and various headers.
    3. Query--cache to see if a local copy is available, and if not, get a copy and save it locally.
    4. Freshness detection--caches see if the cached copy is fresh enough, and if not, ask the server for any updates.
    5. Create response--the cache will construct a response message with a new header and a cached principal.
    6. Send--the cache sends the response back to the client over the network.
    7. Log--The cache optionally creates a log file entry to describe the transaction.
keep the copy fresh Document expirationwith the special HTTP Cache-control and Expires headers, HTTP lets the original server attach an "expiration date" to each document. [Plain]View Plaincopy
  1. Expires:fri, 01:31:39 GMT, Jan
  2. cache-control:max-age=439293
expires and Cache-control expries: Specifies an absolute expiration date. If the expiration date has passed, the document is no longer fresh. The expires header and Cache-control:max-age first do things essentially the same, but the Cache-control header uses the relative time instead of the absolute date (expires uses an absolute expiration date), So we are more inclined to use the newer Cache-control header, and the absolute date depends on the correct setting of the computer clock. Cache-control:The Max-age:max-age value defines the maximum lifetime of a document-the maximum legal lifetime (in seconds) from the time the document is first generated to the document is no longer fresh and unusable. Server re-authenticationJust because the cached document is out of date does not mean that it is actually different from the document that is currently working on the active state on the original server, which simply means that it is time to audit. This is referred to as "server re-Authentication", which indicates that the cache needs to ask if the server document has changed. 1) If the content changes, the cache acquires a new copy of the document, stores it in the location of the old document, and then sends the document to the client. 2) If the content does not change, the cache only needs to get a new header, including a new expiration date, and update the header in the cache. re-verification with conditional methodThe 2 most useful headers for cache re-authentication are (if-modified-since,if-unmodified-since) [corresponds to last-modified] and (If-none-match,if-match) [corresponding to the etag] if-modified-since: Executes the requested method if the document has been modified since the specified date. Can be used in conjunction with the Last-modified server response header to obtain content only when the content has been modified and is different from the cached version.
if-none-match: The server can provide a special label ( Etag, version Identifier) for the document, rather than matching it to the last modified date, which is like a serial number. If the cached label differs from the label in the server document, theIf-none-match header executes the requested method.
the ability of the server to control the cache with the client You can specify expiration policies for documents in several ways that are defined by HTTP
Cache-control:no-store Cache-control:no-cache
cache-control:max-age

"HTTP authoritative guide" reading notes-caching

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.