Application and analysis of asp.net caching

Source: Internet
Author: User

In many of the features offered by ASP.net, caching has the greatest potential impact on application performance compared to all other features of ASP.net, and with caching and other mechanisms, asp.net developers can accept expensive controls (for example, DataGrid) overhead when building a site, without having to worry about how much performance might be affected. In order to maximize caching in your application, you should consider implementing caching at all program levels.

Realize

To implement the page output cache, simply add a OutputCache directive to the page.

<%@ OutputCache duration= "*" varybyparam= "*"%>

As with other page directives, the directive should appear at the top of the ASPX page, before any output. It supports five properties (or parameters), of which two are required.

Duration

Required Properties. The time, in seconds, that the page should be cached. Must be a positive integer.

Location

Specifies where the output should be cached. If you want to specify this parameter, you must be one of the following: Any, Client, downstream, None, Server, or serverandclient.

VaryByParam

Required Properties. The name of the variable in Request, which should produce a separate cache entry. "None" indicates no change. The "*" can be used to create a new cache entry for each variant array. separated by ";" between variables.

VaryByHeader

Changes the cached entry based on the changes in the specified header.

VaryByCustom

Allows you to specify a custom change (for example, "Browser") in Global.asax.

Use a combination of the required Duration and VaryByParam options to handle most situations. For example, if the product catalog allows users to view catalog pages based on CategoryID and page variables, you can cache the product catalog for a period of time using the VaryByParam with the parameter value "Categoryid;page" (if the product is not always changing, an hour is acceptable, so The duration is 3,600 seconds). This creates a separate cache entry for each catalog page of each kind. Each entry will be maintained for one hours from its first request.

VaryByHeader and VaryByCustom are primarily used to customize the appearance or content of a page based on the client accessing the page. The same URL may need to render output for both the browser and the mobile client, so different content versions are cached for different clients. Alternatively, the page may have been optimized for IE, but it needs to be able to completely reduce optimizations (rather than just damaging pages) against Netscape or Opera. The latter example is very common and will provide an example that shows how to achieve this goal:

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.