Web caching knowledge for Web developers-caching data to browser-side net implementations

Source: Internet
Author: User

In reality, the server in the data sent to the browser, part of the data is not updated frequently, if you can cache this part of the data to the browser, will greatly reduce the data transferred, improve the performance of the application. With the expires policy, you can use the HTTP

The caching mechanism of the protocol definition caches the data in the browser. Let's take a look at how net implements caching data in the browser.

protected voidPage_Load (Objectsender, EventArgs e) {        if(request.headers["if-modified-since"] !=NULL&& Timespan.fromticks (DateTime.Now.AddHours (1). Ticks-datetime.parse (request.headers["if-modified-Since"]). Ticks). TotalSeconds < 100)//cache 100 seconds, can be adjusted according to the actual situation. You can also modify the judging criteria. {Response.statuscode=304; Response.statusdescription="Not Modified"; }        Else{Literal1. Text= DateTime.Now.ToString ("YYYY-MM-DD HH:mm:ss");        Setclientcaching (Response,datetime.now); }    }    Private voidsetclientcaching (httpresponse response, DateTime lastmodified) {response.        Cache.setetag (LastModified.Ticks.ToString ()); Response.        Cache.setlastmodified (lastmodified); Response.        Cache.setcacheability (Httpcacheability.public); Response. Cache.setmaxage (NewTimeSpan (7,0,0,0)); Response. Cache.setslidingexpiration (true); }

Web caching knowledge for Web developers-caching data to browser-side net implementations

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.