KeyDependency

KeyDependency

Tracks Key dependencies to other objects in application's Cache.


Constructor

# new KeyDependency(keys, keyDependencyType)

Initializes a new instance of the KeyExpiration class that monitors an array of file paths (to files or directories), an array of cache keys, or both for changes.

Parameters:
Name Type Description
keys Array.<string>

Array of cache keys.

keyDependencyType keyDependencyType

Type specifying operation upon which key dependency is to be triggered.

Example
//Initialize the Cache Cluster 
let cache = await ncache.CacheManager.getCache("demoCache");

// Generate a json object of  customer
let customer = getCustomerObjuect();

// create CacheItem to with your desired object
let cacheItem = new ncache.CacheItem(customer, "Json");

// Add customer in cache
await cache.add(customer.CustomerID, cacheItem);

// Generate a json object of order
let order = getOrderObject();

// Generate an instance of key dependency.
let dependency = new ncache.KeyDependency(customer.CustomerID);

// Note that an item can be dependent on multiple items in cache this can be done like this
// let multipleDependency = await new ncache.KeyDependency([customer.CustomerID, 'Customer:52' ]);

// create CacheItem to with your desired object
cacheItem = new ncache.CacheItem(order, "Json");

// add key dependency
cacheItem.setDependency(dependency);

// Add order in cache with dependency on the customer added before
await cache.add(order.OrderID, cacheItem);

//Any modification in the dependent item will cause invalidation of the dependent item.

Methods

# getCacheKeys() → {Array.<string>}

Return array of cache keys

Returns:

list of keys

Type
Array.<string>

# getKeyDependencyType() → {KeyDependencyType}

Get type specifying operation upon which key dependency is to be triggered.

Returns:

KeyDependency type.

Type
KeyDependencyType

# getStartAfterTicks() → {Number}

Get StartAfterTicks shows the time after which dependency is to be started.

Returns:

The time after which key dependency is started.

Type
Number

# setKeyDependencyType(value)

Enumeration specifying operation upon which key dependency is to be triggered.

Parameters:
Name Type Description
value KeyDependencyType

The KeyDependencyType to be associated with the dependency.