Asp.net Cache

Source: Internet
Author: User

1. Output Caching

With output caching, the final rendered HTML of the page is cached. when the same page is requested again, the control objects are not created, the page life cycle doesn't start, and none of your code executes. instead, the cached HTML is served.

You can cache an ASP. NET page in two ways. the most common approach is to insert the OutputCache directive at the top of your. aspx file, just below the Page directive, as shown here:

<%@ OutputCache Duration= VaryByParam= %>

The Duration attribute instructs ASP. NET to cache the page for 20 seconds.

The OutputCache command is actually asp.net that outputs three response headers to the response header:

VaryByParam = %>

Now when you request the page with additional query string information, ASP. NET will examine the query string. if the string matches a previous request and a cached copy of that page exists, it will be reused. otherwise, a new copy of the p age will be created and cached separately.

2. Caching with Specific Query String Parameters

Setting VaryByParam to the wildcard asterisk (*) is unnecessarily vague. It's usually better to specifically identify an important query string variable by name. Here's an example:

<%@ OutputCache Duration= VaryByParam= %>

In this case, ASP. NET will examine the query string, looking for the ProductID parameter. Requests with different ProductID parameters will be cached separately, but all other parameters will be ignored.

You can specify several parameters as long as you separate them with semicolons:

<%@ OutputCache Duration= VaryByParam= %>

In this case, ASP. NET will cache separate versions, provided the query string differs by ProductID or CurrencyType.

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.