gitmyhub

FusionCache

C# ★ 3.8k updated 12d ago

FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features.

FusionCache is a .NET caching library that prevents common cache failures like stampedes and outages, and supports both in-memory and distributed caches like Redis in one setup.

C#.NETRedisOpenTelemetry.NET Standardsetup: moderatecomplexity 3/5

FusionCache is a caching library for .NET applications written in C#. Caching is the practice of storing frequently needed data in fast memory so that your application does not have to recalculate or re-fetch it from a slower source (like a database) on every request. FusionCache aims to make this easier and more reliable than typical caching setups.

It works as a hybrid cache, meaning it can operate with a single in-memory store or with two layers at once: a fast local layer in memory (L1) and a slower distributed layer like Redis or another shared cache (L2). Using two layers means multiple servers in a cluster all benefit from the shared distributed cache while still keeping the fastest reads from local memory. A backplane component keeps the local caches on all nodes in sync when data changes.

The library addresses several problems that commonly cause caches to misbehave. Cache stampede, for instance, is a situation where many requests all try to rebuild the same missing cache entry at the same time, flooding the database with identical queries. FusionCache prevents this automatically. It also includes a fail-safe mechanism: if the source system is temporarily unavailable when a cached entry expires, it serves the stale (expired) value as a fallback instead of returning an error. Timeouts prevent a slow database or distributed cache from making your application unresponsive.

For observability, the library integrates with OpenTelemetry (a standard way to trace and monitor what is happening in a running application), exposes structured logs through the standard .NET logging interface, and emits events at both high-level and low-level operations. Named caches let an application maintain several independent cache configurations. A tagging system lets you group related entries and expire them together.

FusionCache received a Google Open Source Award in 2021, and is used in production at significant scale. Microsoft uses it in its Data API Builder product. It targets .NET Standard 2.0, which means it runs on older as well as modern versions of .NET.

Where it fits