One, aspx page caching
Page caching is very simple to use, just add a statement at the top of the ASPX page <%@ OutputCache duration= "" varybyparam= "None"%>
This way, the contents of the entire page are cached, the ASP. NET code in the page, the data source is not run during the cache, and the content of the cached page is output directly.
Page caching is for all visitors to this page. So the pressure on the database for 1 visitors and 10,000 visitors, one visit, and 1 million visits is the same.
Second, outpucache parameters
Duration: Cache time, per second
VaryByParam: Cache parameters,
Varybyparam=noneNo parameter cache, can be used for home page;
varybyparam= "*"If you want to create different caches for any of the different query strings, setting varybyparam= "*" will generally be sufficient to set "*".
varybyparam= "id"Because id=2, id=3 is just the different parameters of the page, in order to allow different kinds of news cache, so you can set the varybyparam= "id"
diskcacheable= "True|false"Do you want to put the cache on your hard drive?
Note: Buffer = true; The following settings do not take effect, the page defaults to True
The following is the @ OutputCache instruction for the code sample and the equivalent programming code.
- To store the output cache for a specified duration
Declarative methods:<%@ OutputCache duration= "All" varybyparam= "None"%>
Method of Programming:Response.Cache.SetExpires (DateTime.Now.AddSeconds (60)); Response.Cache.SetCacheability (Httpcacheability.public);
- Store the output cache on the browser client where the request is made
Declarative methods:<%@ OutputCache duration= "" "location=" Client "varybyparam=" None "%>
Method of Programming:Response.Cache.SetExpires (DateTime.Now.AddSeconds (60)); Response.Cache.SetCacheability (httpcacheability.private);
- Store output cache on any HTTP 1.1 cache-capable devices, including proxy servers and clients making requests
Declarative methods:<%@ OutputCache duration= "location=" downstream "varybyparam=" None "%>
Method of Programming:Response.Cache.SetExpires (DateTime.Now.AddSeconds (60)); Response.Cache.SetCacheability (Httpcacheability.public); Response.Cache.SetNoServerCaching ();
- To store the output cache on a WEB server
Declarative methods:<%@ OutputCache duration= "location=" "Server" varybyparam= "None"%>
Method of Programming:TimeSpan freshness = new TimeSpan (0,0,0,60); DateTime now = DateTime.Now; Response.Cache.SetExpires (now. ADD (freshness)); Response.Cache.SetMaxAge (freshness); Response.Cache.SetCacheability (Httpcacheability.server); Response.Cache.SetValidUntilExpires (TRUE);
- When the cache arrives, the output of each HTTP request is used in a different city:
Declarative methods:<%@ OutputCache duration= "varybyparam=" "City"%>
Method of Programming:Response.Cache.SetExpires (DateTime.Now.AddSeconds (60)); Response.Cache.SetCacheability (Httpcacheability.public); response.cache.varybyparams["City" = true;
Update cache:Response.Cache.SetNoServerCaching ();
Asp. NET Cache OutputCache's C # background settings