CacheManager.Core with NCache
CacheManager.Core is an open-source, lightweight caching abstraction layer for .NET applications. It acts as a unified interface for various caching providers, allowing developers to manage complex, multi-tiered (N-Tier) caching scenarios with minimal code. Each cache provider is represented as a cache handle and CacheManager.Core coordinates read, write, update, remove, expiration, and event operations across the configured handles.
When integrated with NCache, CacheManager.Core can use NCache as a distributed cache handle within its multi-tier caching pipeline. This allows applications to combine fast local caching with NCache’s scalable distributed cache layer for shared data across multiple application instances. Through this integration, applications can benefit from NCache features such as clustered caching, absolute and sliding expiration, cache synchronization, and distributed data storage, while continuing to use CacheManager.Core as a single, consistent caching interface.
Note
This feature is supported only in the NCache OpenSource edition.
Important
CacheManager is supported in NCache 5.3.6.2 and onwards.
Key Features
The key features of CacheManager.Core integration with NCache are as follows:
Unified Cache API: Applications can use standard CacheManager.Core APIs such as
Add,Put,Get,Remove, andClear, while the NCache integration maps these operations to the corresponding NCache cache operations.Multi-Tier Cache Pipeline: NCache can be configured as one of the cache handles in CacheManager.Core’s ordered N-Tier cache pipeline, alongside other cache tiers such as in-memory or custom cache providers.
Distributed Cache Handle: NCache participates in the CacheManager.Core pipeline as a distributed cache handle, allowing cached data to be stored and retrieved from a scalable distributed cache layer.
Expiration Mapping: The integration supports mapping CacheManager.Core cache item expiration metadata to NCache expiration behavior, including absolute and sliding expiration.
Backplane Support: NCache Pub/Sub Backplane is used to notify application instances about cache changes so that local L1 cache handles can be synchronized or invalidated.
How CacheManager.Core Works with NCache
CacheManager.Core uses a configurable cache handle pipeline to coordinate cache operations across one or more cache layers. Each cache provider is represented as a cache handle. In the NCache integration, NCacheCacheHandle<T> implements the CacheManager.Core cache handle abstraction and maps CacheManager.Core operations to the corresponding NCache cache operations.
Cache Handle Pipeline
A typical CacheManager.Core configuration with NCache may include an in-memory cache handle and an NCache cache handle. The in-memory handle can serve as a local cache layer, while the NCache handle provides distributed cache storage.
CacheManager.Core manages the cache handle pipeline and coordinates operations across the configured handles. NCache is responsible for storing, retrieving, updating, and removing distributed cache entries through the NCache cache instance configured for the application.
Read Operation
When the application calls Get(key):
- CacheManager.Core checks the configured cache handles in order.
- The first cache handle that contains the key returns the cached value.
- If the value is found in a lower-level cache handle, CacheManager.Core may populate higher-level handles according to the configured behavior.
- If the value is not found in any configured handle, the operation returns
null.
When NCache is configured as part of the cache handle pipeline, it acts as the distributed cache layer that can store shared cached data for multiple application instances.
Write Operation
When the application calls Put(key, value) or Add(key, value):
- CacheManager.Core processes the operation through the configured cache handle pipeline.
- The NCache cache handle maps the operation to the corresponding NCache cache operation.
Putworks as an upsert operation.Addinserts the item only when the key does not already exist.- CacheManager.Core raises the related lifecycle event when the operation succeeds.
Expiration Control
The NCache CacheManager.Core integration supports absolute and sliding expiration-based cache control. CacheManager.Core expiration metadata is used by the NCache cache handle to apply the corresponding expiration behavior to entries stored in NCache.
Backplane Synchronization
The NCache CacheManager.Core integration provides NCacheCacheBackplane, which implements CacheManager.Core backplane support using NCache Pub/Sub. The backplane is used for cache memory invalidation across application instances.
When one application instance updates or removes cached data:
- The local CacheManager.Core instance performs the cache operation.
- The NCache backplane publishes a cache change notification.
- Other application instances receive the notification.
- Their local cache handles can be invalidated based on the received event.
This helps reduce stale reads when multiple application instances use local cache handles with a shared NCache distributed cache.
Note
CacheManager.Core manages the cache handle pipeline, read/write coordination, lifecycle events, and expiration metadata. NCache provides the distributed cache handle, NCache connectivity, distributed cache storage, and Pub/Sub-based backplane invalidation.
Important
Tag-based eviction is not supported in the CacheManager.Core integration with NCache.
In This Section
NCache as CacheManager.Core Provider
Learn how to configure NCache as a CacheManager.Core cache handle and backplane provider.
CacheManager.Core API Usage
Explore examples of common CacheManager.Core operations with NCache, including add, put, get, remove, expiration, events, and backplane behavior.