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