HTTP protocol for ASP. NET and Client Cache

Source: Internet
Author: User

ArticleWe will discuss how to use ASP. NET Server Technology to optimize Client Cache policies and make these policies configurable and scalable. We need to understand the impact of relevant HTTP attributes on client cache, and how ASP. NET controls these attributes to implement our cache policy.

Basic HTTP knowledge

As the discussion involves client caching, we should first briefly introduce how the HTTP protocol controls the client caching. This involves the last-modified and etag attributes of the HTTP header.

Last-modified

When the browser requests a URL for the first time, the server returns 200, and the content is the resource you requested, at the same time, there is a last-modified attribute to mark the last modification time of this file on the service end. The format is similar to this:

Last-modified: Fri, 12 May 2006 18:53:33 GMT

When the client requests this URL for the second time, it adds an attribute to the header and asks if the file has been modified after this time:

If-modified-since: Fri, 12 May 2006 18:53:33 GMT

If the file on the server side has not been modified, the returned status is 304 and the content is blank, which saves the amount of data transmitted. If the files on the server have been modified, the returned results are similar to those in the first request.

Etag

Similar to last-modified, since rfc2616 (that is, HTTP/1.1) does not specify the format of etag, make sure that it is enclosed in double quotation marks, so you can use the file hash or even the last-modified directly. The following is the format returned by the server:

Etag: "50b1c1d4f775c61: df3"

The query update format of the client is as follows:

If-None-Match: W/"50b1c1d4f775c61: df3"

If etag does not change, status 304 is returned and no result is returned, which is the same as last-modified.

Expires

This attribute is as direct as we use httpresponse. expiresabsolute in ASP. It declares that the browser should request the URL again after the expiration of a certain time. The format is:

Expires: Sun, 10 Feb 2002 16:00:00 GMT

Note that httpresponse. expiresabsolute is not recommended in ASP. NET. Now we should use httpresponse. cache. setexpires.

Pragma

The value we usually use is no-cache, which is the same as the no-Cache value in cache-control. The Pragma format is as follows:

Pragma: No-Cache
Cache-control

This is a collection property that can contain many sub-attributes and allows users to expand new sub-attributes. Common subattributes include:

Max-age-timeout in seconds, overwrite the expires attribute.
Public-can be stored in the shared cache.
Private-it can only be stored in the private cache.
No-Cache-the cache is not allowed.
No-store-the cache is not allowed in persistent media.
No-transform-the storage system cannot be converted.

Related Article

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.