1. Make the database support SqlCacheDependency
In the. Net Framework 2.0 installation directory (usually WINDOWS \ Microsoft. NET \ Framework \ v2.0.xxxxx), there is an aspnet_regsql.exe. This command line tool can help us make the database support the SqlCacheDependency feature.
Run the "aspnet_regsql-S server name-E-d database name-ed-t traced data table-et" command to enable the corresponding data table to support SqlCacheDependency.
(PS: The parameter can use "aspnet_regsql /?" For query)
2. web. config Configuration
<System. web>
<! -Configure the Cache node so that the website supports SqlCacheDependency->
<Caching>
<SqlCacheDependency enabled = "true" pollTime = "1200">
<Databases>
<Add name = "sqlonstringname =" database link string "/>
</Databases>
</SqlCacheDependency>
</Caching>
</System. web>
3. Set the outputCache on the page.
<% @ OutputCache Duration = "9999" VaryByParam = "none" SqlDependency = "Northwind: Employees" %>
Northwind is the tracing database, and the following Employees is the data table to be tracked.
Basically, data binding is the same as normal. When the records in the data table are modified, the page will be cached again (not immediately. Wait a moment, because you have to wait for the program to cache the page again ^_^ !!)