Http-web Cache

Source: Internet
Author: User

Cache
web缓存可以自动保存常见的文档副本的Http设备,当web请求到达时,如果本地已有缓存副本,则直接响应。下面会解释http如何保持副本的新鲜度,以及缓存和服务器通信的问题。
    1. Redundant data transfer is
    2. Bandwidth bottleneck: The general LAN bandwidth is relatively high, the metropolitan area network bandwidth is low, if you can set the cache in the LAN, you can quickly respond to users.
    3. Instantaneous congestion can prevent unexpected events, and instantly burst the server, generating where.
    4. Distance delay
    5. Hits and misses
      The cache checks whether the replica is the latest on the server, called the freshness check.

HTTP provides several tools for caching objects to be validated

    • If-modified-since Header
    • In the validation hit
    • The server returns an up-to-date object when the authentication is not hit
    • object is deleted cache will also delete object
Cache Hit Ratio
中等规模来说,40%就已经可以了。这是指客户端请求被缓存响应的频率。字节命中率,就是缓存传送的字节占总字节的百分比。

Differentiate between hit and miss scenarios

You can use the date header and the age header to determine whether the response is from the cache or the original server.

Private cache
web浏览器中有内建的私有缓存,大多数浏览器会将常用的文档,缓存到个人电脑的磁盘或者内存中。还可以查看缓存内容和过期时间。
Shared Proxy Cache
这是缓存代理服务器,被称为代理缓存。可以提供给多个用户访问。
Hierarchical structure of proxy caches
可以使用多级缓存,在靠近客户端的地方使用小的廉价的缓存,更高层次,采用更大的,功能更强的缓存。
Process steps for caching
    1. Receive
    2. Analytical
    3. Query – The query caches the copy locally, if there is a requested resource, and the cached object has some meta information, including how much time the object has been in the cache and how many times it has been used.
    4. Freshness detection the HTTP cache retains the server document for a period of time, in which the document is considered fresh and is provided directly to the client without contacting the server. Once the document has been stuck for a long time, the cache is to be validated before the document is supplied. The request header that the client sends to the cache can force the cache to be validated or completely avoid inflammation.
    5. Creating a response cache inserts freshness information (cache-control,age,expires header) into the client's response, and the cache should not adjust the date header, which represents the dates that the original server originally produced the object.
    6. Send
    7. Log
Keep the Copy Fresh
通过Cache-Control首部和Expires首部,http让原始服务器向每个文档附加一个过期时间。过期之前,可以无限制的使用缓存副本,除非客户端请求中包含了,阻止提供已缓存或者未验证的资源首部。
    1. Expiration time and trial period Cache-control:max-age: This value defines the maximum legal lifetime that is generated from the document until it is no longer fresh. The unit is in seconds. Expires: Specifies an absolute expiration date, GMT time.
    2. Server re-authentication if only the cache time expires, it does not mean that the document must have changed. This is called server re-authentication, which can be verified by the following conditional validation method.
    3. The conditional validation method re-verifies that HTTP allows caching to send a conditional get to the server, echoing the object body only when the document is different from the cache. 5 Conditional request headers were provided, the 2 most commonly used: If-modified-since,if-none-match.
    4. If-modified-since:date if the document has been modified since the specified date, get is executed, new documents with the new header are returned to the cache, and the new header has a new expiration time, in addition to other content. If it does not expire, it will return a 304 yards and will typically return a new expiration time.
    5. If-none-match entity label re-authentication using this header, there are a few reasons: some documents may be periodically modified, although the content has not changed, but the change time has changed. 2. Some documents have been modified, but the changes made are not important and do not require the world's caches to reload the data. To address these issues, HTTP allows users to use version identifiers called ' Entity tags '. If the entity label does not match again, the new content and the new label (ETAG) are returned.
    6. The weak authenticator of the strength validator, only changes when the content changes greatly.
    7. When to use entity labels and last modified date if the server returns an entity label, you can use the tag validator, and if the last-modified value is returned, the client can use If-modified-since. If all is provided, you can use these two kinds. http1.1 It is best to send an entity label, with the last modification time.
Ability to control caching
http定义了几种方式来指定文档过期之前,可以将其缓存多长时间。Cache-Control:no-store,no-cache,must-revalidate,max-age,附件一个Expires日期到首部中去。还可以不附加过期时间,让缓存自己确定过期时间。

1. No-store prevents replication of the response, and, like a non-caching proxy, deletes the object after the response has been forwarded.
2. The no-cache response can be stored in the local cache. It is allowed to be used by clients only after the freshness of the original server has been re-verified.
3. The number of seconds that the Max-age document is considered valid from the time the server is transmitted. If it is set to 0, it should be refreshed every time it is accessed.
4. Expires header does not recommend this, because many server clock settings are not synchronized, or incorrect.
5. Must-revalidate is not available to client services in the absence of server re-authentication.
6. The tentative expiration cache itself calculates a maximum effective time.
7. Client freshness limits the Web browser, when refreshing or reloading a button, typically publishes an additional Cache-control header URL request. Force the cache to be re-validated.

Http-web Cache

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.