In depth understanding of ASP.NET2.0 caching of Cache technology

  • 2020-05-19 04:31:39
  • OfStack

ASP.NET2.0 provides some new technical features to improve the performance of the program. Among them, the caching technology is a very important one, which provides a very good local data caching mechanism, thus effectively improving the performance of data access.
Data caching (DataCaching) is a technique for storing data in an in-memory cache (and sometimes in a hard-disk cache). When the data itself changes infrequently and is accessed more frequently, this technique can greatly improve the efficiency of data access.
1. Page output cache
(1) add cache
< %@OutputCacheDuration="60"VaryByParam=none% >
statements < %@% > Where :Duration="60" represents the cache duration of 60 seconds, and the VaryByParam property is used to specify the output of a particular version of the web page, which parameter changes < %@OutputCache% > The VaryByParam attribute must be added to configuration directive 1. Even if you do not use the version attribute, add it, but set it to none.
(2) callback cache
< %@OutputCacheDuration=60VaryByParam=stata% >
According to the lll. aspx? The contents of stata= are cached separately
The following method can be refreshed based on the content
 
<scriptrunat="server"> 
SharedFunctionGetCurrentDate(ByValcontextAsHttpContext)AsString 
ReturnNow.ToString() 
EndFunction 
</script> 
<asp:SubstitutionID="Substitution1"runat="server"MethodName="GetCurrentDate"/> 

2. Database cache
In ASP.NET2.0, you can set the cache parameters of the data table through the data source.
CacheDuration: represents the duration of the cache. The default is Infinite(unlimited)
CacheExpirationPolicy: cache policy. There are two Settings :Absolute and Sliding. When set to the latter, the time limit is to immediately refresh the data in the cache and continue caching the updated data.
CacheKeyDependency: can be used with SQLServer2005 database.
EnableCaching: the default is False, that is, the data cache is not used. When this property is changed to True, the data cache can be started.
SqlCacheDependecy: cache dependency. For example, setting pubs:authors indicates the establishment of a dependency between the authors data table in the database Pubs and its data cache.
Sometimes the data table is too large, the cache may take up too much memory space. You can cache the data in the cache area of the hard disk.
1: configure in the web page < %@OutputCacheDuration="3600"VaryByParam="none"DiskCacheable="true"% >
2: specify the cache size of the hard disk in the Web.config file. The configured statement is as follows:
 
<system.web> 
<caching> 
<outputCache> 
<diskCacheEnabled="true"maxSizePerApp="2"/> 
</outputCache> 
</caching> 
</system.web> 

Where diskCacheEnabled="true" is used to start the hard disk cache function; maxSizePerApp="2" is used to determine the size of the cache area. The maximum size of the cache area determined here is 2M. As the access speed to the hard disk is slow, the hard disk cache is only suitable for long cache duration (1 hour in this case).

3. The buffer pool
Data cache technology greatly improve the alert to the speed of data access, but it may cause data not 1 cause problems. So the above is only applicable to data cache technology, data change frequency is not high. Now, ASP NET2. 0 SQLServer2005 new version combined with database, the data cache function was greatly improved, both simplified the use process, and improved the processing measures, one of the most prominent 1 point is combined with database automatically solve the problem of the failure data.
0 in ASP. NET2. In order to solve the problem of data failure, through the new class SQLCacheDependency set up with a new generation of database "SQL cache dependencies (SQLExpressdependencycaching)", the relationship can make database can automatically monitor the status of the data table, as the data table has changed, immediately start the database itself triggers the corresponding data in a buffer zone becomes invalid.
This method can also be used for SQL 7/2000 databases, but you must configure the monitored databases first to use them. This configuration method is cumbersome, but once configured, it is easy to use. For earlier versions of SQLServer or other types of databases (such as Oracle), this 1 capability is not available.
Configure the database connection pool
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 > aspnet_regsql.exe
Run the asp.netsqlServer configuration wizard
Aspnet_regsql. exe � S "\ DBNAME" � E � d "pubs" � ed
- Ewindows authorization
� ed enabled
Aspnet_regsql. exe � S "\ DBNAME" � E � D "pubs" � et � t "authors"
Change the cache when pubs.authors changes
< %@OutputCacheDuration="9999999"VaryByParam="none"SqlDependency="pubs.authors"% >
Cache configuration
 
<caching> 
<outputCache> 
<diskCacheenabled="true"maxSizePerApp="2"/> 
</outputCache> 
<outputCacheSettings> 
<outputCacheProfiles> 
<addname="CacheFor60Seconds"duration="60"/> 
</outputCacheProfiles> 
</outputCacheSettings> 
<!-- 
<sqlCacheDependencyenabled="true"pollTime="1000"> 
<databases> 
<addname="PubsDB"connectionStringName="pubsConnectionString"/> 
</databases> 
</sqlCacheDependency> 
--> 
</caching> 

Related articles: