ASP. NET 2.0 cache translation draft
Original article: http://www.codeproject.com/useritems/Caching_Mechanism.asp
Namespace: system. Web. caching, which is an important part of the infrastructure of ASP. NET. For example, session is stored in the cache.
Cache objects have two levels of access control: public and private. Private is reserved by system components. Only public is reserved.ProgramYou can use the ienumerable interface to enumerate data in the public state.
ASP. NET provides 3 intermediate cache:
? Page Level --- cache the entire page;
? Page fragment --- controls such as. ASCs can be cached as part of the page;
? Programmatic caching --- programming to cache data through the public cache API;
In ASP. NET 2.0, the page level cache mechanism is extended to support the cache of dependent databases. That is, the page
The cache data on the level page and the data in the database table are set to dependent. When the data in the data table changes, the page level cache will automatically expire, which solves the problem of page
The level cache time is difficult to control.
Let's look at an example:
In ASP. NET 1.xCode:
<% @ Outputcache duration = "3600" varybyparam = "prodid" %>
Page Level Code in ASP. NET 2.0:
<% @ Outputcache duration = "3600" varybyparam = "prodid" sqldependency = "northwind: Products" %>
Note: although the cache time for the page is 3600 seconds, if the data in the northwind: Products table changes, the cache will become invalid.
Description: sqldependency is a new attribute, which consists of two parts: data source and table name. It is configured in: Web. config. For details, see the relevant documentation.
ASP. NET 2.0 also provides two cache-related classes: sqlcachedependency and cachedependency.