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, and distributed data storage, while continuing to use CacheManager.Core as a single, consistent caching interface.
Important
For the NCache OpenSource edition, CacheManager.Core integration is supported in NCache OSS 5.3.6.2 and later.
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:
NCacheCacheBackplaneprovides backplane support for CacheManager.Core applications. Cache-change notifications can be used to coordinate cache handles according to the configured cache pipeline and provider behavior.
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,
Getreturns the default value ofT(nullfor reference types).
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 Support
The NCache CacheManager.Core integration provides NCacheCacheBackplane for CacheManager.Core backplane operations.
The backplane is configured together with the cache handle and uses a registered NCache configuration key. CacheManager.Core can use backplane notifications to coordinate cache handles across application instances according to the configured cache pipeline and provider behavior.
Note
CacheManager.Core coordinates cache entries across the configured cache handles. When a backplane is configured, it also publishes invalidation notifications to synchronize cache state across application instances. However, this synchronization is notification-based and does not provide transactional or strong-consistency guarantees, particularly if notifications are delayed or lost, or if the backplane is unavailable.
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 backplane support.
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.