How to realize the SqlCacheDependency of ASP.net 2.0

Source: Internet
Author: User
Asp.net|cache|sql

Previously used cache, always beware of the data version of the cache and the database version of the data is inconsistent, although through the trigger + file IO Implementation of the file cache can also achieve cache data updates, but each application produces an IO file, not economical, the other trigger performance is not very high, So often in addition to delete changes, delete the cache key value to achieve, but there may be missing places. 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>

This configures a cache-dependent database, and the ObjectDataSource object's enablecaching on the page is set to True., and then set the SqlCacheDependency property to Atlasdemodb: Simpledemo1,atlasdemodb the name of the cached database configured for web.config, SimpleDemo1 is a table name under that database.
In this way, the system will also have the following problems:


Database "Atlasdemodb" is not enabled for SQL cache notification.

To enable the database for SQL cache notification, use the System.Web.Caching.SqlCacheDependencyAdmin.EnableNotifications method, or the command-line tool aspnet_regsql. To use this tool, run the aspnet_regsql.exe-? For more information.
According to the above, run aspnet_regsql.exe more annoying, you can fill in the Page_Load event


System.Web.Caching.SqlCacheDependencyAdmin.EnableTableForNotifications ( system.configuration.configurationmanager.connectionstrings["Atlasdemodbconnectionstring"]. ConnectionString, "SimpleDemo1");
This will allow you to use the SqlCacheDependency.



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.