When using Cache in the past, I was always careful about the inconsistency between the data version in the Cache and the data version in the database. Although the file cache dependency implemented through triggers + file IO can also achieve timely updates of cached data, each application generates an IO file. It is not very economical, and the trigger performance is not very high, so when adding, deleting or modifying, it is often achieved by deleting the cache key value, but there may be some omissions. SqlCacheDependency is implemented in asp.net 2.0. This article describes how to implement SqlCacheDependency in asp.net 2.0:
First, add the following code to the web.config system.web node file:
<caching>
<sqlCacheDependency enabled="true">
<databases>
<add name="AtlasDemoDb" connectionStringName="AtlasDemoDbConnectionString" pollTime="12000"></add>
</databases>
</sqlCacheDependency>
</caching>
In this way, a cache-dependent database is configured, and the EnableCaching of the ObjectDataSource object in the page is set to true. Then set the SqlCacheDependency property to AtlasDemoDb:SimpleDemo1, AtlasDemoDb is the cache database name configured in web.config, and SimpleDemo1 is A table name under the database.
Just like this, the system will also have the following problems:
Database 'AtlasDemoDb' is not enabled for SQL cache notifications.
To enable a database for SQL cache notifications, use the System.Web.Caching.SqlCacheDependencyAdmin.EnableNotifications method, or the command-line tool aspnet_regsql. To use this tool, run "aspnet_regsql.exe -?" for details.
As mentioned above, it is troublesome to run aspnet_regsql.exe. You can fill it in the Page_Load event.
System.Web.Caching.SqlCacheDependencyAdmin.EnableTableForNotifications(System.Configuration.ConfigurationManager.ConnectionStrings["AtlasDemoDbConnectionString"].ConnectionString, "SimpleDemo1");
This way you can use SqlCacheDependency. I'll test the performance of this method tomorrow. I’m too sleepy today, so I’ll go to bed first
http://www.cnblogs.com/jillzhang/archive/2006/08/15/477914.html