Asp. NET Cache OutputCache's C # background settings

Source: Internet
Author: User

  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

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.