Understanding the HTTP protocol for ASP.net and client caching

Source: Internet
Author: User
Tags client
Asp.net| Cache | client Preface

This series of articles will discuss how to optimize client caching policies through ASP.net server-side technology, and make this strategy configurable and extensible. We want to understand the impact of the relevant attributes on the client cache from the HTTP protocol, to how ASP.net controls these properties to implement our caching strategy.

   HTTP Basic knowledge

Since the discussion involves client-side caching, it is a simple introduction to how the HTTP protocol controls client caching, which involves attributes such as last-modified and ETag of HTTP headers.

Last-modified

When the browser first requests a URL, the server-side return status is 200, the content is the resource you requested, and there is a last-modified attribute that marks the last time the file was modified at the service end, similar in format:

Last-modified:fri, May 2006 18:53:33 GMT

When the client requests this URL for the second time, a property is added to the header asking if the file has been modified after that time:

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

If the server-side files have not been modified, the return status is 304 and the contents are empty, thus saving the amount of data transferred. If the server-side files have been modified, the return is similar to the first request.

ETag

Similar to last-modified, because RFC2616 (that is, http/1.1) does not specify what format ETag should be, just make sure you enclose it in double quotes, so you can use the hash of the file, or even directly with the last-modified, The following is the format returned by the server side:

ETag: "50b1c1d4f775c61:df3"

The client's query update format is like this:

if-none-match:w/"50b1c1d4f775c61:df3"

If ETag does not change, it returns state 304 and does not return, as is the case with last-modified.

Expires

This property is as straightforward as we use httpresponse.expiresabsolute in ASP, declaring that the browser should request the URL again after the expiration of such time, using the format:

Expires:sun, Feb 2002 16:00:00 GMT

Note that Httpresponse.expiresabsolute is not recommended in ASP.net, now we should use HttpResponse.Cache.SetExpires.

Pragma

Usually the value we use is No-cache, which is the same as using No-cache values in Cache-control, Cache-control below. The use format of pragma is as follows:

Pragma:no-cache
Cache-control

This is a collection-type property that can contain many child properties and allows the user to extend new child properties. Common child properties include the following:

Max-age-Timeout in seconds, overriding expires properties.
Public-allows to be saved in the shared cache.
Private-only allowed to be saved in a private cache.
No-cache-caching is not allowed.
No-store-caching is not allowed in persistent media.
No-transform-The storage system is not allowed to 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.