Initializes a new instance of the CacheDependency class that monitors a file or directory for changes and indicates when change tracking is to begin.

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


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


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.
Type: System..::..DateTime
The time when change tracking begins.


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. The tracking start time is set to 10 minutes in the future.
 Copy imageCopy
   // Make key1 dependent on a file.
CacheDependency dependency = new CacheDependency(Server.MapPath("isbn.xml"), DateTime.Now.AddMinutes(10));
Cache cache = NCache.InitializeCache("myCache");
   cache.Insert("key1", "Value 1", dependency);

See Also