Initializes a new instance of the CacheDependency class that monitors a file or directory for changes.

Namespace: Alachisoft.NCache.Runtime.Dependencies
Assembly: Alachisoft.NCache.Runtime (in Alachisoft.NCache.Runtime.dll) Version: (


public CacheDependency(
	string fileName
Visual Basic
Public Sub New ( 
	fileName As String
Visual C++
	String^ fileName


Type: System..::..String
The path to a file or directory that the cached object is dependent upon. When this resource changes, the cached object becomes obsolete and is removed from the cache.


If the directory or file specified in the fileName parameter is not found in the file system, it will be treated as a missing file. If the file is created after the object with the dependency is added to the [!:Cache], the cached object will be removed from the [!:Cache].

For example, assume that you add an object to the [!:Cache] with a dependency on the following file path: c:\stocks\xyz.dat. If that file is not found when the CacheDependency object is created, but is created later, the cached object is removed upon the creation of the xyz.dat file.


The following example demonstrates code that creates an instance of the CacheDependency class when an item is inserted in the [!:Cache] with a dependency on an XML file.
 Copy imageCopy
   // Make key1 dependent on a file.
CacheDependency dependency = new CacheDependency(Server.MapPath("isbn.xml"));
Cache cache = NCache.InitializeCache("myCache");
   cache.Insert("key1", "Value 1", dependency);

See Also