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: 4.1.0.0 (4.1.0.0)

Syntax

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

Parameters

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

Remarks

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.

Examples

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.
CopyC#
   // 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