Establishes a relationship between an item stored in an ASP.NET application's Cache object and either a specific SQL Server database table or the results of a SQL Server 2005 query. This class cannot be inherited.
Assembly: System.Web (in System.Web.dll)
Thetype exposes the following members.
|CreateOutputCacheDependency||Creates a dependency relationship between an item that is stored in an ASP.NET application's OutputCache object and a SQL Server database table.|
|DependencyDispose||Releases the resources used by the CacheDependency class and any classes that derive from CacheDependency. (Inherited from CacheDependency.)|
|Dispose||Releases the resources used by the CacheDependency object. (Inherited from CacheDependency.)|
|Equals(Object)||Determines whether the specified Object is equal to the current Object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|FinishInit||Completes initialization of the CacheDependency object. (Inherited from CacheDependency.)|
|GetHashCode||Serves as a hash function for a particular type. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|GetUniqueID||Retrieves a unique identifier for a object. (Overrides CacheDependency::GetUniqueID().)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|NotifyDependencyChanged||Notifies the base CacheDependency object that the dependency represented by a derived CacheDependency class has changed. (Inherited from CacheDependency.)|
|SetUtcLastModified||Marks the time when a dependency last changed. (Inherited from CacheDependency.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
On all supported versions of SQL Server (Microsoft SQL Server 7.0, Microsoft SQL Server 2000, and SQL Server 2005) the class monitors a specific SQL Server database table. When the table changes, items associated with the table are removed from the Cache, and a new version of the item is added to the Cache.
The class also supports integration with the System.Data.SqlClient::SqlDependency class when using a SQL Server 2005 database. The query notification mechanism of SQL Server 2005 detects changes to data that invalidate the results of an SQL query and removes any cached items associated with the SQL query from the System.Web.Caching::Cache.
You can use the class to add items to your application's Cache that are dependent on either a SQL Server database table or on an SQL query when using SQL Server 2005. You can also use this class with the @ OutputCache directive to make an output-cached page or a user control dependent on a SQL Server database table. Finally, you can use the class with the @ OutputCache page directive to make an output-cached page dependent on the results of an SQL query when using SQL Server 2005. Query notification using SQL Server 2005 is not supported on the @ OutputCache directive for user controls.
For this class to work correctly when using table-based notifications, the database and any tables that you want to make dependencies on must have notifications enabled. You can enable notifications by calling methods of the SqlCacheDependencyAdmin class or by using the Aspnet_regsql.exe command-line tool. In addition, the proper configuration settings must be included in the application's Web.config file.
Using a object with SQL Server 2005 query notification does not require any explicit configuration. Consult the SQL Server 2005 Books Online for information about restrictions on the types of Transact-SQL queries that are allowed when using query notification.
The following example shows an ASP.NET Web.config file that enables table-based dependencies on a SQL Server database table.
<configuration> <connectionStrings> <add name="Northwind" connectionString="Data Source=(local); Initial Catalog=northwind; Integrated Security=true"; providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <caching> <sqlCacheDependency enabled = "true" pollTime = "60000" > <databases> <add name="northwind" connectionStringName="Northwind" pollTime="9000000" /> </databases> </sqlCacheDependency> </caching> </system.web> </configuration>
|Walkthrough: Using ASP.NET Output Caching with SQL Server||Building ASP .NET Web Applications in Visual Studio|
The following code example uses the SqlDataSource and GridView controls to display a database table. When the page is loaded, the page attempts to create a object. After the object is created, the page adds an item to the Cache with a dependency on the object. You should use exception handling similar to that shown here.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.