Establishes a dependency relationship between an item stored in an ASP.NET application's System.Web.Caching.Cache object and a file, cache key, an array of either, or another System.Web.Caching.CacheDependency object. The System.Web.Caching.CacheDependency class monitors the dependency relationships so that when any of them changes, the cached item will be automatically removed.
See Also: CacheDependency Members
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 System.Data.DataSet object based on data in an XML file. You can add the System.Data.DataSet to the cache with a System.Web.Caching.CacheDependency object that makes the System.Data.DataSet dependent on the XML file. If the XML file changes, the System.Data.DataSet is removed from the cache.
You can add items with dependencies to your application's cache with the Cache.Add(string, object, CacheDependency, DateTime, TimeSpan, CacheItemPriority, CacheItemRemovedCallback) and erload:System.Web.Caching.Cache.Insert methods. You cannot use the Cache.Item(string) property to add items to the cache with dependencies.
To set up a dependency, you create an instance of the System.Web.Caching.CacheDependency class, specifying the files, keys, or directories on which the item is dependent, and then pass the dependency to the Cache.Add(string, object, CacheDependency, DateTime, TimeSpan, CacheItemPriority, CacheItemRemovedCallback) or erload:System.Web.Caching.Cache.Insert method. The System.Web.Caching.CacheDependency 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 System.Web.Caching.Cache object).