Constructor CacheDependency
CacheDependency()
Default constructor for CacheDependency class.
Declaration
public CacheDependency()
CacheDependency(CustomDependency)
Creates a CacheDependency instance from Custom Dependency.
Declaration
public CacheDependency(CustomDependency customDependency)
Parameters
Type | Name | Description |
---|---|---|
CustomDependency | customDependency | CustomDependency instance. |
CacheDependency(ExtensibleDependency)
Creates a CacheDependency instance from Extensible Dependency.
Declaration
public CacheDependency(ExtensibleDependency extensibleDependency)
Parameters
Type | Name | Description |
---|---|---|
ExtensibleDependency | extensibleDependency | ExtensibleDependency instance. |
CacheDependency(String)
Initializes a new instance of the CacheDependency class that monitors a file or directory for changes.
Declaration
public CacheDependency(string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | 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. |
Remarks
If the directory or file specified in the fileNames 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.
Let's 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 how to create an instance of the CacheDependency class when an item is inserted in the cache with a dependency on an XML file.
// Make key1 dependent on a file.
CacheDependency dependency = new CacheDependency(Server.MapPath("isbn.xml"));
Cache cache = NCache.InitializeCache("demoClusteredCache");
cache.Insert("key1", "Value 1", dependency);
CacheDependency(String, DateTime)
Initializes a new instance of the CacheDependency class that monitors a file or directory for changes and indicates when change tracking is to begin.
Declaration
public CacheDependency(string fileName, DateTime start)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | 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. |
System.DateTime | start | The time against which to check the last modified date of the directory or file. |
Remarks
If the directory or file specified in the fileNames 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.
Let's 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 how to create 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.
// Make key1 dependent on a file.
CacheDependency dependency = new CacheDependency(Server.MapPath("isbn.xml"), DateTime.Now.AddMinutes(10));
Cache cache = NCache.InitializeCache("demoClusteredCache");
cache.Insert("key1", "Value 1", dependency);
CacheDependency(String[])
Initializes a new instance of the CacheDependency class that monitors an array of file paths (to files or directories) for changes.
Declaration
public CacheDependency(string[] fileNames)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | fileNames | An array of file paths (to files or directories) that the cached object is dependent upon. When any of these resources change, the cached object becomes obsolete and is removed from the cache. |
Remarks
If any of the files or directories in the array were to change or be removed from the array, the cached item becomes obsolete and is removed from the application's cache object.
Also, if any of the directories or files specified in the fileNames parameter is not found in the file system, they are treated as missing files. If any of them are created after the object with the dependency is added to the cache, the cached object will be removed from the cache. Let's 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.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | fileNames contains a null reference. |
CacheDependency(String[], DateTime)
Initializes a new instance of the CacheDependency class that monitors an array of file paths (to files or directories) for changes and specifies a time when change monitoring begins.
Declaration
public CacheDependency(string[] fileNames, DateTime start)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | fileNames | An array of file paths (to files or directories) that the cached object is dependent upon. When any of these resources change, the cached object becomes obsolete and is removed from the cache. |
System.DateTime | start | The time against which to check the last modified date of the directory or file. |
Remarks
If any of the files or directories in the array were to change or be removed from the array, the cached item becomes obsolete and is removed from the application's cache object.
Also, if any of the directories or files specified in the fileNames parameter is not found in the file system, they are treated as missing files. If any of them are created after the object with the dependency is added to the cache, the cached object will be removed from the cache. Let's 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.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | fileNames contains a null reference. |
CacheDependency(String[], String[])
Initializes a new instance of the CacheDependency class that monitors an array of file paths (to files or directories), an array of cache keys, or both for changes.
Declaration
public CacheDependency(string[] fileNames, string[] cacheKeys)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | fileNames | An array of file paths (to files or directories) that the cached object is dependent upon. When any of these resources change, the cached object becomes obsolete and is removed from the cache. |
System.String[] | cacheKeys | An array of cache keys that the new object monitors for changes. When any of these cache keys change, the cached object associated with this dependency object becomes obsolete and is removed from the cache. |
Remarks
If any of the files or directories in the array were to change or be removed from the array, the cached item becomes obsolete and is removed from the application's cache object.
Also, if any of the directories or files specified in the fileNames parameter is not found in the file system, they are treated as missing files. If any of them are created after the object with the dependency is added to the cache, the cached object will be removed from the cache. Let's 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 code fragment demonstrates how to insert an item into your application's cache with a dependency on a key to another item placed in the cache. Since this method uses array syntax, you must define the number of keys the item you are adding to the cache is dependent on.
CacheDependency(String[], String[], DateTime)
Initializes a new instance of the CacheDependency class that monitors an array of file paths (to files or directories), an array of cache keys, or both for changes.
Declaration
public CacheDependency(string[] fileNames, string[] cacheKeys, DateTime start)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | fileNames | An array of file paths (to files or directories) that the cached object is dependent upon. When any of these resources change, the cached object becomes obsolete and is removed from the cache. |
System.String[] | cacheKeys | An array of cache keys that the new object monitors for changes. When any of these cache keys change, the cached object associated with this dependency object becomes obsolete and is removed from the cache. |
System.DateTime | start | The time against which to check the last modified date of the directory or file. |
Remarks
If any of the files or directories in the array were to change or be removed from the array, the cached item becomes obsolete and is removed from the application's cache object.
Also, if any of the directories or files specified in the fileNames parameter is not found in the file system, they are treated as missing files. If any of them are created after the object with the dependency is added to the cache, the cached object will be removed from the cache. Let's, 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.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | fileNames or cacheKeys contains a null reference. |
CacheDependency(String[], String[], CacheDependency)
Initializes a new instance of the CacheDependency class that monitors an array of file paths (to files or directories), an array of cache keys, or both for changes. It also makes itself dependent upon a separate instance of the CacheDependency class.
Declaration
public CacheDependency(string[] fileNames, string[] cacheKeys, CacheDependency dependency)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | fileNames | An array of file paths (to files or directories) that the cached object is dependent upon. When any of these resources change, the cached object becomes obsolete and is removed from the cache. |
System.String[] | cacheKeys | An array of cache keys that the new object monitors for changes. When any of these cache keys change, the cached object associated with this dependency object becomes obsolete and is removed from the cache. |
CacheDependency | dependency | Another instance of the CacheDependency class that this instance is dependent upon. |
Remarks
If any of the files or directories in the array were to change or be removed from the array, the cached item becomes obsolete and is removed from the application's cache object.
Also, if any of the directories or files specified in the fileNames parameter is not found in the file system, they are treated as missing files. If any of them are created after the object with the dependency is added to the cache, the cached object will be removed from the cache. Let's, 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.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | fileNames or cacheKeys contains a null reference. |
CacheDependency(String[], String[], CacheDependency, DateTime)
Initializes a new instance of the CacheDependency class that monitors an array of file paths (to files or directories), an array of cache keys, or both for changes. It also makes itself dependent upon another instance of the CacheDependency class and a time when the change monitoring begins.
Declaration
public CacheDependency(string[] fileNames, string[] cacheKeys, CacheDependency dependency, DateTime start)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | fileNames | An array of file paths (to files or directories) that the cached object is dependent upon. When any of these resources change, the cached object becomes obsolete and is removed from the cache. |
System.String[] | cacheKeys | An array of cache keys that the new object monitors for changes. When any of these cache keys change, the cached object associated with this dependency object becomes obsolete and is removed from the cache. |
CacheDependency | dependency | Another instance of the CacheDependency class that this instance is dependent upon. |
System.DateTime | start | The time against which to check the last modified date of the directory or file. |
Remarks
If any of the files or directories in the array were to change or be removed from the array, the cached item becomes obsolete and is removed from the application's cache object.
Also, if any of the directories or files specified in the fileNames parameter is not found in the file system, they are treated as missing files. If any of them are created after the object with the dependency is added to the cache, the cached object will be removed from the cache. Let's, 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.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | fileNames or cacheKeys contains a null reference. |