
CacheDependency | 517
Caching
Namespace
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Returned By
System.Web.HttpContext.Cache, System.Web.HttpRuntime.Cache, System.Web.UI.Page.Cache, System.Web.UI.
UserControl.Cache
CacheDependency
System.Web.Caching (system.web.dll)
disposable
sealed class
Cache dependencies allow the validity of a cache item to be based on a file or direc-
tory on the web server, or on another cache item. When the dependency object
changes, the dependent cache item is invalidated and removed automatically. To set
up a dependency, you first create a CacheDependency object that references the file, direc-
tory, or cache item upon which the dependency will be based. You then use the Cache.
Insert( ) method to add the dependent cache item, with the CacheDependency object supplied
as a parameter.
The overloaded constructor of the CacheDependency class determines the type of depen-
dency. You can pass a single string argument to set up a dependency on a file or
directory (CacheDependency(Server.MapPath("data.xml")) or you can use a second string argu-
ment with the key of another cache item (CacheDependency(Nothing, "MyData")). Other
versions of the constructor allow you to specify an array of strings specifying files or
cache objects. If any one file or object changes, the dependent cache item will be
invalidated.
The CacheDependency ...