Establishes a dependency relationship between an item stored in an ASP.NET application's Cache object and a file, cache key, an array of either, or another object. The class monitors the dependency relationships so that when any of them changes, the cached item will be automatically removed.
Assembly: System.Web (in System.Web.dll)
If you add an item to the cache that is dependent on another object, such as a file or array of files, the dependent item is automatically removed from the cache when the object changes. For example, suppose you create a DataSet object based on data in an XML file. You can add the DataSet to the cache with a object that makes the DataSet dependent on the XML file. If the XML file changes, the DataSet is removed from the cache.
To set up a dependency, you create an instance of the class, specifying the files, keys, or directories on which the item is dependent, and then pass the dependency to the Add or Cache.Insert method. The instance can represent a single file or directory, an array of files or directories, or an array of files or directories along with an array of cache keys (these represent other items stored in the Cache object).
The following code example demonstrates using the HasChanged property to determine whether a changed since the previous request for an item in the Cache. The dt value passed in the start parameter is set to DateTime.Now.
// Insert the cache item. CacheDependency dep = new CacheDependency(fileName, dt); cache.Insert("key", "value", dep); // Check whether CacheDependency.HasChanged is true. if (dep.HasChanged) Response.Write("<p>The dependency has changed."); else Response.Write("<p>The dependency has not changed.");
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.