Custom Cache Data Dependencies
NCache provides flexible ways to determine data invalidation using various dependencies. However, you can implement your custom logic for dependency if none of the built-in invalidation strategies fulfill your requirements.
In custom dependency, you can implement your custom logic which defines when certain data becomes invalid. Here, the concept of multithreading is incorporated, meaning that instead of executing each item sequentially, multiple threads perform expiration simultaneously. For example, you can implement a custom dependency that makes a call to a web service for the validation of data depending on your application's functionality.
Custom Cache Dependencies in NCache
There are three distinct custom dependency classes provided to you by NCache. The first one is known as ExtensibleDependency class that allows you to implement your custom expiry logic against which data is expired one item at a time. All you need to do is inherit your dependency class from ExtensibleDependency
and override its HasChanged property.
The second class is BulkExtensibleDependency which allows multiple expirations against one call. Instead of the HasChanged
property, the Bulk Extensible Dependency provides an alternate EvaluateBulk method that evaluates multiple items at a time.
The third dependency class provided by NCache is NotifyExtensibleDependency, where the user is responsible for providing the dependency logic that calls a delegate provided by NCache to invoke that logic to remove data from the cache.
Like expiration, the cache cleanup thread periodically calls the HasChanged
property and EvaluateBulk
method, and on returning true, the items are removed from the cache. The NotifyExtensibleDependency
, however, doesn’t depend on the cleanup thread for removing items from the cache. It deploys its own handler on the cache that is responsible for removing items from the cache.
See Also
Sync Cache using Bulk Extensible Dependency
Sync Cache using Notify Extensible Dependency