FusionCache with NCache
FusionCache is a hybrid caching library for .NET applications. It combines a fast local in-memory cache, also known as L1 cache, with an optional distributed cache, also known as L2 cache. This helps applications reduce repeated database calls, improve response time, and continue serving cached data even during temporary backend failures.
Note
This feature is currently supported in the NCache OpenSource edition.
Important
FusionCache is supported in NCache 5.3.6.2 and onwards.
In a distributed or load-balanced application, multiple application servers may run the same application at the same time. Each server can maintain its own local L1 cache. While this improves performance, it can also create stale data problems because one server may update or remove a cache entry while another server still has the old value in memory.
NCache can be used with FusionCache through two separate integrations:
NCache.Microsoft.Extensions.Caching.OpenSourcefor using NCache as FusionCache’s distributed L2 cache.NCache.OSS.ZiggyCreatures.FusionCache.Backplanefor using NCache as FusionCache’s Backplane provider to synchronize L1 cache changes.
When NCache is used with FusionCache, applications can benefit from both local in-memory speed and distributed cache consistency.
Why Use FusionCache with NCache?
In a single-server application, local memory caching may be sufficient because all cached data remains within one application instance. However, in a multi-server environment, each server maintains its own local L1 cache, which can lead to stale or inconsistent data. For example, if Node A updates, removes, expires, or clears a cached product record, Node B may still have the older version in its local memory and continue serving it to users. NCache helps address this by acting as a shared distributed cache where multiple application servers can access the same cached data, and as a synchronization backplane that publishes cache change notifications across nodes so each server can update or invalidate its local L1 entries accordingly.
How FusionCache Works with NCache
When an application requests data, FusionCache follows a layered cache lookup process.
Read Flow
When data is requested, FusionCache first checks the local L1 cache. If the entry is found, the value is returned immediately and no Backplane notification is required because the cache state has not changed. If the entry is not available in L1, FusionCache checks the L2 distributed cache. When the value is found in L2, it is returned to the application and stored again in L1 for faster future access. This is still part of the read path and does not normally require a cluster-wide Backplane notification. However, if the entry is not found in either L1 or L2, FusionCache executes the factory method or retrieves the data from the original data source. Once the fetched value is stored in cache according to the configured options, the operation effectively becomes a write/update operation, and a Backplane notification can be published so other nodes can update or invalidate their local L1 entries.
Note
A cache hit in L1 or L2 is treated as a read operation and does not require a Backplane notification. A cache miss that causes the factory or database call to run and then stores a new value is treated as a cache update, so it can trigger a Backplane notification.
Write Flow
When data is written, updated, removed, or expired, FusionCache first applies the change to the local L1 cache. If an L2 distributed cache is configured, the corresponding cache state is also updated in the distributed cache. When a Backplane is configured, FusionCache publishes a cache change notification so other application nodes can receive the update and invalidate, expire, remove, or refresh their matching local L1 entries. This helps keep local memory caches synchronized across nodes. Depending on the configured fail-safe options, FusionCache may also retain expired values temporarily so they can be used as fallback data during temporary failures.
In This Section
NCache as FusionCache Provider
Learn how to configure NCache as the distributed L2 cache provider for FusionCache.
NCache as FusionCache Backplane Provider
Learn how to configure NCache as a FusionCache Backplane provider to synchronize cache changes across multiple application nodes.