A Preliminary Study on Using ASP. NET cache is critical (1)

Source: Internet
Author: User

Cache is a technology used to store data in memory and ASP. one of the important features provided by NET, for programmers, understand ASP. the working principle of NET cache is very useful for programming.

ASP. NET has a variety of objects to be cached, including the data extracted from the database, the static pages generated by the aspx page, and even the compiled assembly. The rational use of cache can greatly improve the performance of ASP. NET. The following describes the cache mechanism in ASP. NET.

Cache category

In ASP. NET, most caching mechanisms are stored in cache objects, that is, part of the server memory. When a user requests data, if the data has been cached, the data extracted by the user is directly returned from the server, rather than from the database and other underlying databases. This is helpful for improving performance. The following describes several cache mechanisms in ASP. NET.

Assembly Cache

To put it simply, this kind of cache is provided by ASP. NET without the developer's involvement. That is, when the first request is sent to the server, the Page class and related Assembly are compiled. When the next request is sent, the cached compilation is accessed instead of re-compilation. The CLR will automatically detect code changes. If the code changes, the relevant code will be re-compiled at the next visit.

Data Source Cache

Data Source cache, as its name implies, is the way to use the data source control to cache the obtained data. These controls include SqlDataSource and ObjectDataSource. As an abstract class, performancecontrol exposes the following attributes for caching:

The data source control caches the data retrieved by the SelectMethod attribute within a period of time when CacheDuration acquires or sets the expiration behavior of the cache, this behavior and duration can be combined to describe the cache behavior of the data source control. CacheKeyDependency gets or sets a user-defined key dependency, the key depends on the necklace to all data cache objects created by the data source control. EnableCaching gets or sets a value that indicates whether the ObjectDataSource control enables data cache.

It is very easy to use. You only need to set the cache-related attributes. For example, if you want to cache the current data source for 10 seconds, you only need to set the EnableCaching attribute and the CacheDuration attribute as follows. The working principle of this method can be expressed as follows:

SQL Cache Dependency

You should note that the preceding data source control also exposes the CacheKeyDependency attribute, which is used to implement SQL Cache Dependency. When the content of the database table changes, update the corresponding cache, which is dependent on the underlying database, just as Dependency indicates. The following describes two ways to implement SQL Cache Dependency.


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.