• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

Class CacheDependency

Tracks cache dependencies, which can be files, directories, or keys to other objects in application's cache. This class cannot be inherited.

Inheritance
System.Object
CacheDependency
AggregateCacheDependency
CustomDependency
DBCacheDependency
ExtensibleDependency
FileDependency
KeyDependency
NosDBDependency
OracleCacheDependency
SqlCacheDependency
Assembly: Alachisoft.NCache.Runtime.dll
Syntax
[Serializable]
public class CacheDependency : IDisposable, IBinaryProtocolSerializable
Remarks

You can add items with dependencies to your application's cache with the Add and Insert methods.

When you add an item to an application's cache object and, in doing so, define a cache dependency for that item, an instance of the CacheDependency class is created automatically to track changes to the files, keys, or directories you have specified. This helps you avoid losing changes made to the object between the time it is created and the time it is inserted into the cache. The CacheDependency instance can represent a single file or directory, an array of files or directories, or an array of files or directories along with an array of cache keys (these represent other items stored in the cache object).

Constructors

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[], 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.

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.

Fields

DEPENDENCY_COUNT_OVERHEAD

Declaration
protected const int DEPENDENCY_COUNT_OVERHEAD = 4
Field Value
Type Description
System.Int32

DEPENDENCY_TYPE_OVERHEAD

Declaration
protected const int DEPENDENCY_TYPE_OVERHEAD = 1
Field Value
Type Description
System.Int32

sizeInBytes

Declaration
protected int sizeInBytes
Field Value
Type Description
System.Int32

Properties

Dependencies

Contains the list of dependencies for the cache item.

Declaration
public List<CacheDependency> Dependencies { get; }
Property Value
Type Description
System.Collections.Generic.List<CacheDependency>

List of dependencies for the cache item.

Methods

AddDependencies(CacheDependency[])

This method is used to add dependencies for the cache item.

Declaration
protected void AddDependencies(params CacheDependency[] dependencies)
Parameters
Type Name Description
CacheDependency[] dependencies

Array of cache dependencies.

DependencyDispose()

Releases custom resources used by the CacheDependency object.

Declaration
protected virtual void DependencyDispose()
Remarks

Releases the resources used by the CacheDependency object. Must be overriden by custom CacheDependency objects.

Dispose()

Releases the resources used by the CacheDependency object.

Declaration
public virtual void Dispose()
Remarks

Releases the resources used by the CacheDependency object.

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Community
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top