ASP. NET cache Overview (Cache learning summary MSDN)

Source: Internet
Author: User

ASP. NET uses two basic caching mechanisms to provide caching functions. The first mechanism is the application cache, which allows you to cache generated data, such DataSet Or a custom Report Business Object. The second mechanism is the page output cache, which saves the page processing output and reuses the saved output when the user requests the page again, instead of processing the page again.

Page output Cache

Page output cache stores the processed ASP. NET page content in the memory. This mechanism allows ASP. NET to send page responses to the client without having to go through the page processing lifecycle again. The page output cache provides two types of page cache models: full page cache and partial page cache. The full-page cache allows you to store all the page content in the memory and use it to complete client requests. Partial-page cache allows you to cache part of the page content, while other parts are dynamic content. Partial-page cache can be replaced by control cache and cache. The control cache is also called the segment cache. This method allows information to be contained in a user control, and the user control is marked as cacheable to cache part of the page output. This method caches specific content on a page and does not cache the entire page. Therefore, you need to recreate the entire page each time. The cache replacement is the opposite to the control cache. This method caches the entire page, but the sections in the page are dynamic. With the cache replacement mechanism, you can configure the page to be cached, but mark individual parts of the page as non-cached. In this case, you can add controls to the non-cacheable part to dynamically create these controls for each user and each page request.

Automatically remove data

ASP. NET can remove data from the cache for one of the following reasons:

  • Because the memory on the server is insufficient, it starts a process called "cleaning.

  • Because the items in the cache have expired.

  • Because the item dependency has changed.

Expired

In addition to cleanup, ASP. NET automatically removes cache items when they expire. When adding an item to the cache, you can set its expiration time as described in the following table.

Expiration type

Description

Adjustable expiration

Specifies how long an item expires after the last access. For example, you can set an item to expire 20 minutes after the last access in the cache.

Absolutely expired

Specify that an item expires at the specified time, regardless of the Access frequency. For example, you can set an item to expire at or four hours later.

Dependency

You can configure the lifetime of one of the cached items as dependent on other application elements. ASP. NET cache supports the dependencies described in the following table.

Dependency

Description

Key dependency

Items in the application cache are stored in key/value pairs. Key dependency items can depend on another key in the application cache. If the original item is removed, the item with the key dependency is also removed. For example, you can add a cache item named ReportsValid and then cache several reports dependent on the ReportsValid key. When the ReportsValid item is removed, all cache reports dependent on it will also be removed from the cache.

File dependency

Items in the cache depend on external files. If the file is modified or deleted, the cache item is also removed.

SQL dependency

Items in the cache depend on changes to tables in the Microsoft SQL Server 2005, SQL Server 2000, or SQL Server 7.0 database. For SQL Server 2005, items in the cache can depend on a row in the table.

Aggregate Dependencies

Use AggregateCacheDependency Items in the class cache depend on multiple elements. If any dependency item changes, it will be removed from the cache.

Custom Dependencies

You can use the dependencies created by your own code to configure items in the cache. For example, you can create a custom Web service cache dependency. When the Web Service is called to obtain a specific value, the dependency will be removed from the cache.

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.