Dependencies in NCache
NCache offers various features to improve the performance of applications that rely heavily on data sources, such as its various Cache Dependencies. NCache ensures real-time synchronization and maintains data integrity through these dependencies.
They let you establish a relationship between different cache items within a single cache, between cache items present in different caches, and even with external sources such as files and databases. The following sections discuss these dependencies in detail.
Key Dependency
To ensure efficient management and retrieval of cached data NCache offers Key Dependency. This dependency associates cached data with specific keys to organize its cached data and improve access time. NCache offers two types of Key Dependencies, Multilevel and Multiple. In Multilevel Dependency, a cache item can depend on a number of other cache items forming a 1:1 relationship. However, in Multiple Dependency, a cache item can depend on more than one item in the cache hence forming a 1:n relationship between cache items.
Multi-Cache Dependency
To maintain data integrity and consistency NCache allows you to keep two different caches synchronized through Multi-Cache Dependency. This dependency ensures that when an item is updated or removed from one cache, it has the same effect on the synchronized cache. Multi-Cache Dependency lets you synchronize two different caches using item-level notifications provided by NCache. Whenever an item is updated or removed from one cache, a key-based notification is fired to the other to synchronize data.
Database Dependency
To keep your cache synchronized with the database, NCache offers Database Dependencies (Notification-based and Polling-based). They enable automatic cache invalidation upon relevant data change in the database (either through polling or firing event notifications). Notification-based dependencies offer real-time updates but can be complex, while polling-based dependencies are simpler to implement, but may introduce delays and increase overhead.
NCache natively supports Database Dependency with SQL Server and Oracle. However, if you are using any database that does not provide support for data change notifications, you can use the NCache Extensible Dependency - where NCache polls your database to know about any updates in the database and synchronize the cache accordingly, to write a customized dependency provider for your database.
File Dependency
NCache offers File Dependency to invalidate cache data while using non-relational data sources. It allows users to link cached data to specific files ensuring that the cache data is automatically invalidated when the associated files are modified. This dependency is critical to maintain data integrity in scenarios where the cached data is influenced by external file changes, such as configuration files or data files. NCache triggers File Dependency if:
- The dependency file is removed/modified.
- The dependency folder is removed/modified.
- The dependency file/folder comes into existence during the cleanup interval after being absent at the time of creation.
Aggregate Dependency
NCache also provides you with the option to combine different dependencies with the same cache data, through the Aggregate Dependency. This lets you associate multiple dependencies of different types with a single cache item. For instance, you can associate a Key and File Dependency with an item using Aggregate Dependency and the item will be invalidated based on whichever dependency is triggred first. Essentially, you can add the Key, File, and Database Dependencies together using the Aggregate Dependency.