Asp.net Cache Technology and cache implementation method (1/4)

Source: Internet
Author: User

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 asp tutorial x 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 your product directory allows users to view the directory Page Based on categoryid and page variables, you can use 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.
Varybyheader and varybycustom are mainly used to customize the appearance or content of the page based on the client accessing the page. The same url may need to be rendered and output for both the browser and mobile client. Therefore, different content versions must be cached for different clients. Alternatively, the page may have been optimized for ie, but it must be completely optimized for netscape or opera (not just to destroy the page ). The next example is very common. We will provide an example to illustrate how to achieve this goal:
Example: varybycustom is used to support browser customization.
To make each browser have a separate cache entry, the value of varybycustom can be set to "browser ". This function has been built into the cache module and will insert a separate page Cache version for each browser name and major version.
<% @ Outputcache duration = "60" varybyparam = "none" varybycustom = "browser" %>
Segment cache, user control output Cache
Caching the entire page is usually not feasible because some parts of the page are customized for users. However, the rest of the page is shared by the entire application. These parts are most suitable for cache using fragment caching and user controls. Menu and other layout elements, especially those dynamically generated from the data source, should also be cached in this way. If necessary, you can configure the Cache control to be changed based on changes to its control (or other attributes) or any other changes supported by the page-level output cache. Using hundreds of pages of the same control group can also share the cache entries of those controls, rather than retaining a separate Cache version for each page. 1 2 3 4

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.