Add Dependency to Existing Cached Item
If data has been added to a cache without a dependency defined, NCache allows
you to add any of the dependency types to this existing data without any need of
an update function. This can be done using the AddDependency
function provided
by the NCache API.
The following code shows how to add a dependency with existing data.
To utilize the API, include the following namespace in your application:
Alachisoft.NCache.Runtime.Dependencies.
string key1 = "Product:1001";
string key2 = "Product:1002";
//precondition: items with keys "Product:1001" and Product:1002" are already in cache
try
{
cache.AddDependency(key2, new KeyDependency(key1), false);
}
catch (OperationFailedException ex)
{
// handle exception
}