To enable a table to use SQL cache dependencies, you first need to run the aspnet_regsql.exe tool from the command line with these parameters:
aspnet_regsql -S servername -U login -P password -ed -d databasename -et -t tablename
If your table name contains a space, then wrap the table name in quotation marks, for example.
aspnet_regsql -S servername -U login -P password -ed -d databasename -et -t "table name"
In your web.config you need to add the caching section:
<system.web> <caching> <sqlCacheDependency enabled = "true" pollTime = "60000" > <databases> <add name="northwind" connectionStringName="Northwind" pollTime="9000000" /> </databases> </sqlCacheDependency> </caching> </system.web>
When you add an item to your cache, you use the SqlCacheDependency object to configure the relationship between the cached object and the base table:
SqlCacheDependency dependency = new SqlCacheDependency("databasename", "tablename"); Cache.Add(key, object, dependency);
source share