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 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 System.Web.Caching.Cache, the cached object will be removed from the
System.Web.Caching.Cache.
For example, assume that you add an object to the System.Web.Caching.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 System.Web.Caching.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 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 System.Web.Caching.Cache, the cached object will be removed from the
System.Web.Caching.Cache.
For example, assume that you add an object to the System.Web.Caching.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 System.Web.Caching.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 System.Web.Caching.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 System.Web.Caching.Cache, the cached object will be removed from the System.Web.Caching.Cache.For example,
assume that you add an object to the System.Web.Caching.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 |
|
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 when change tracking begins. |
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 System.Web.Caching.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 System.Web.Caching.Cache, the cached object will be removed from the System.Web.Caching.Cache.For example,
assume that you add an object to the System.Web.Caching.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 |
|
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 System.Web.Caching.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 System.Web.Caching.Cache, the cached object will be removed from the System.Web.Caching.Cache.For example,
assume that you add an object to the System.Web.Caching.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 System.Web.Caching.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 System.Web.Caching.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 when change tracking begins. |
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 System.Web.Caching.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 System.Web.Caching.Cache, the cached object will be removed from the System.Web.Caching.Cache.For example,
assume that you add an object to the System.Web.Caching.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 |
|
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 System.Web.Caching.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 System.Web.Caching.Cache, the cached object will be removed from the System.Web.Caching.Cache.For example,
assume that you add an object to the System.Web.Caching.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 |
|
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 when change tracking begins. |
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 System.Web.Caching.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 System.Web.Caching.Cache, the cached object will be removed from the System.Web.Caching.Cache.For example,
assume that you add an object to the System.Web.Caching.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 |
|