In ASP. among the many features provided by NET, cache supports the features I like most, compared with ASP. all other features of. NET, the cache has the greatest potential impact on the application performance, using the cache and other mechanisms, ASP. NET developers can accept the additional overhead when building a site using a control with a large overhead (for example, DataGrid), without worrying that the performance will be greatly affected. To maximize the use of caching in applications, you should consider implementing caching at all program levels.
Implementation
To implement the page output cache, you only need to add an OutputCache command to the page.
<% @ OutputCache Duration = "60" VaryByParam = "*" %>
Like other page commands, this command should appear at the top of the ASPX page, that is, before any output. It supports five attributes (or parameters), two of which are required.
Duration
Required attribute. The time when the page should be cached, in seconds. Must be a positive integer.
Location
Specify the location where the output should be cached. To specify this parameter, it must be Any, Client, Downstream, None, Server, or ServerAndClient.
VaryByParam
Required attribute. The name of the variable in the Request. These variable names should generate separate cache entries. "None" indicates no change. "*" Can be used to create a cache entry for each variable group. Variables are separated.
VaryByHeader
Changes cache entries based on changes in the specified header.
VaryByCustom
Allow you to specify custom changes (for example, "Browser") in global. asax ").
The combination of the required Duration and VaryByParam options can be used to handle most cases. For example, if the product directory allows you to view the directory page based on categoryID and Page variables, you can set the parameter value to "categoryID; page "VaryByParam caches the Product directory for a period of time (if the product is not changed at any time, one hour is acceptable, so the duration is 3600 seconds ). This creates separate cache entries for each directory page of each category. Each entry is counted from its first request for one hour.
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