NCache 4.6 - Online Documentation

Adding Data with Key Dependency

Data in cache can depend on items like a file on some location, a record in database, results of a particular query or another cached item, such that any change in the item which has dependent data in NCache invalidates the data. In that case all dependent data must be reloaded or removed from cache otherwise data will become stale.
An object can be specified as being dependent on another key at the time of addition. Note that the only keys present in cache can be specified as key dependency. Nonexistent key specified as key dependency will result in OperationFailedException.
      To utilize the KeyDependency API, include the following namespace in your application: Alachisoft.NCache.Runtime.Dependencies.
The following code shows how to add an item with key dependency:
            cache.Add(key1, "Product:1001");
            //add key2 with dependency on key1
            cache.Add(key2, "Product:1002", new KeyDependency(key1), Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,                               CacheItemPriority.Normal);
            //removing/inserting/deleting key1 will remove key2 because of its dependency
            cache.Insert(key1, "Product:1001_updated");
            object value = cache.Get(key2);
            if (value == null)
                //dependent item removed successfully due to key dependency
                //dependent item not removed
        catch (Exception ex)
            // handle exception

In Key Dependency an item can only depend on an existing item, thus all dependency keys must exist in cache before an item can depend on them.
See Also