NCache 4.6 - Online Documentation

Add Dependency to Existing Cached Item

 
If data has been added to cache without dependency, NCache allows to add any of the dependency supported by NCache, with this existing data without any need of updating data. This can be done using AddDependency API of NCache.
 
      To utilize the API, include the following namespace in your application: Alachisoft.NCache.Runtime.Dependencies.
 
The following code shows how to add dependency with existing data.
 
            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
            }
 
To add file dependency use:
 
cache.AddDependency(key, new FileDependency(filepath), false);
 
Any dependency can be added with the existing cached item with the same API.
 
 
See Also