ASP. NET cache Overview

Source: Internet
Author: User
Tags microsoft sql server 2005 server memory

Generate high-performance, scalable Web Applications Program One of the most important factors is the ability to store these items in the memory during the first request, whether they are data objects, pages or some parts of pages. These items can be cached or stored on Web servers or other software in the request stream, such as a proxy server or browser. This avoids re-creation of information that satisfies previous requests, especially information that requires a large amount of processing time or resources.
ASP. NET provides two methods to create cache types for high-performance web applications. The first type is the output cache, which allows the dynamic pages and user control responses to be stored on any device with the HTTP 1.1 caching function in the output stream (from the initiating server to the requesting browser. When a subsequent request occurs, the page or user control is not executed. Code The cached output is used to satisfy the request. The second type of cache is the application data cache, which can be used to programmatically store arbitrary objects (such as application data) to the server memory, to save the time and resources required to recreate these objects.

ASP. NET 2.0 supports the following caches:
1. Page output Cache
Save the ASP. NET page in the server's memory. When a user requests this page, the relevant data is directly output from the memory, without having to go through the page to process the lifecycle again.
The page output cache provides two 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, partial-page cache allows you to cache part of the page content, and other parts are dynamic content. You can configure page cache for each page, or create a cache configuration file in the web. config file. With the cache configuration file, you can use these settings on multiple pages by defining the cache settings only once.
Partial-page cache can work in two ways: Control Cache And Cache replacement . Control Cache Allow information to be contained in a user control, and mark the user control as a cache 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. For example, if you want to create a page that displays a large amount of dynamic content (such as stock information), some of which are static content (such as weekly summary), you can place the static content in the user control, and allow caching of the content. Cache replacement This is the opposite of the control cache. In this way, the entire page is cached, but some parts of the page are marked as non-cached.
2. Application Cache
The application cache provides a programming method that stores any data in the memory through key/value pairs. The application cache status is similar to that of the application. However, unlike the application state, the data in the application cache is easy to lose, that is, the data is not stored in the memory throughout the application lifecycle. The advantage of application cache is that ASP. NET manages the cache, which removes items in the cache when the items expire, are invalid, or the memory is insufficient. You can also configure the application cache to notify the application when an item is removed.

Automatically remove data
ASP. NET can remove data from the cache for one of the following reasons:
1. Due to insufficient memory on the server, a process called "cleaning" is started.
2. Because the items in the cache have expired.
3. The item dependency has changed.
Note:
Clear : The process of deleting items from the cache when the memory is insufficient. If some items are not accessed for a period of time, or are marked as low-priority when added to the cache, these items are removed.
Expired : When cache items expire, ASP. NET will automatically remove these items from the cache. 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 a cached item to be dependent on other application elements, such as a file or database. When the element on which the cache item depends is changed, ASP. NET removes the item from the cache. 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 addReportsvalidAnd then cache several dependent onReportsvalidKey report. WhenReportsvalidWhen an 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. For more information, see cache in ASP. NET using the sqlcachedependency class.

Aggregate Dependencies

Items in the cache by using the aggregatecachedependency class 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.

 

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.