ZiggyCreatures.FusionCache 2.0.0

Prefix Reserved
dotnet add package ZiggyCreatures.FusionCache --version 2.0.0                
NuGet\Install-Package ZiggyCreatures.FusionCache -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZiggyCreatures.FusionCache --version 2.0.0                
#r "nuget: ZiggyCreatures.FusionCache, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ZiggyCreatures.FusionCache as a Cake Addin
#addin nuget:?package=ZiggyCreatures.FusionCache&version=2.0.0

// Install ZiggyCreatures.FusionCache as a Cake Tool
#tool nuget:?package=ZiggyCreatures.FusionCache&version=2.0.0                

FusionCache

FusionCache logo

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

It was born after years of dealing with all sorts of different types of caches: memory caching, distributed caching, http caching, CDNs, browser cache, offline cache, you name it.

So I tried to put together these experiences and came up with FusionCache.

FusionCache diagram

Being a hybrid cache means it can transparently work as either a normal memory cache (L1) or as a multi-level cache (L1+L2), where the distributed 2nd level (L2) can be any implementation of the standard IDistributedCache interface: this will get us better cold starts, better horizontal scalability, more resiliency and overall better performance.

FusionCache also includes an optional backplane for realtime sync between multiple nodes and advanced resiliency features like cache stampede protection, a fail-safe mechanism, soft/hard timeouts, eager refresh, full observability via logging and OpenTelemetry, tagging and much more.

It's being used in production on real-world projects with huge volumes for years, and is even used by Microsoft itself in its products like Data API Builder.

It's also compatible with the new HybridCache from Microsoft, thanks to a powerful integration.

๐Ÿ† Award

On August 2021, FusionCache received the Google Open Source Peer Bonus Award: here is the official blogpost.

๐Ÿ“• Getting Started

With ๐Ÿฆ„ A Gentle Introduction you'll get yourself comfortable with the overall concepts.

Want to start using it immediately? There's a โญ Quick Start for you.

Curious about what you can achieve from start to finish? There's a ๐Ÿ‘ฉโ€๐Ÿซ Step By Step guide.

In search of all the docs? There's a page for that, too.

๐Ÿ“บ Media

More into videos?

I've been lucky enough to be invited on some shows and podcasts here and there: you can find them in the Media section.

A good example is when the fine folks at On .NET invited me on the show to allow me to mumbling random caching stuff.

On .NET Talk

โœ” Features

FusionCache has a lot of features, let's see them grouped together:

Resiliency
Performance & Scalability
Flexibility
Observability

โญ Quick Start

Just install the ZiggyCreatures.FusionCache Nuget package:

PM> Install-Package ZiggyCreatures.FusionCache

Then, let's say we have a method that loads a product from the database:

Product GetProductFromDb(int id) {
	// DATABASE CALL HERE
}

(This is using the sync programming model, but it would be equally valid with the newer async one)

Then we create a FusionCache instance:

var cache = new FusionCache(new FusionCacheOptions());

or, if using dependency injection:

services.AddFusionCache();

Now, to get the product from the cache and, if not there, get it from the database in an optimized way and cache it for 30 sec:

var id = 42;

cache.GetOrSet<Product>(
	$"product:{id}",
	_ => GetProductFromDb(id),
	TimeSpan.FromSeconds(30)
);

That's it.

๐Ÿ–ฅ๏ธ Simulator

Distributed systems are, in general, quite complex to understand.

When using FusionCache with the distributed cache, the backplane and auto-recovery the Simulator can help us seeing the whole picture.

FusionCache Simulator

๐Ÿงฐ Supported Platforms

FusionCache targets .NET Standard 2.0 so any compatible .NET implementation is fine: this means .NET Framework (the old one), .NET Core 2+ and .NET 5/6+ (the new ones), Mono 5.4+ and more (see here for a complete rundown).

NOTE: if you are running on .NET Framework 4.6.1 and want to use .NET Standard packages Microsoft suggests to upgrade to .NET Framework 4.7.2 or higher (see the .NET Standard Documentation) to avoid some known dependency issues.

๐Ÿ†Ž Comparison

There are various alternatives out there with different features, different performance characteristics (cpu/memory) and in general a different set of pros/cons.

A feature comparison between existing .NET caching solutions may help you choose which one to use.

๐Ÿ’ผ Is it Production Ready โ„ข๏ธ ?

Yes!

FusionCache is being used in production on real world projects for years, happily handling billions of requests.

Considering that the FusionCache packages have been downloaded more than 10 million times (thanks everybody!) it may very well be used even more.

Oh, and it is being used in products by Microsoft itself, like Data API Builder!

๐Ÿ’ฐ Support

Nothing to do here.

After years of using a lot of open source stuff for free, this is just me trying to give something back to the community.

If you really want to talk about money, please consider making โค a donation to a good cause of your choosing, and let me know about that.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (28)

Showing the top 5 NuGet packages that depend on ZiggyCreatures.FusionCache:

Package Downloads
ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis

FusionCache backplane for Redis based on the StackExchange.Redis library

ZiggyCreatures.FusionCache.Serialization.NewtonsoftJson

FusionCache serializer based on Newtonsoft Json.NET

ZiggyCreatures.FusionCache.Serialization.SystemTextJson

FusionCache serializer based on System.Text.Json

Auth0Net.DependencyInjection

Dependency Injection, HttpClientFactory & ASP.NET Core extensions for Auth0.NET

ZiggyCreatures.FusionCache.OpenTelemetry

Add native OpenTelemetry support to FusionCache.

GitHub repositories (8)

Showing the top 5 popular GitHub repositories that depend on ZiggyCreatures.FusionCache:

Repository Stars
Azure/data-api-builder
Data API builder provides modern REST and GraphQL endpoints to your Azure Databases and on-prem stores.
neozhu/CleanArchitectureWithBlazorServer
This is a repository for creating a Blazor Server dashboard application following the principles of Clean Architecture
TurnerSoftware/CacheTower
An efficient multi-layered caching system for .NET
ikyriak/IdempotentAPI
A .NET library that handles the HTTP write operations (POST and PATCH) that can affect only once for the given request data and idempotency-key by using an ASP.NET Core attribute (filter).
JasonBock/Rocks
A mocking library based on the Compiler APIs (Roslyn + Mocks)
Version Downloads Last updated
2.0.0 1,587 1/19/2025
2.0.0-preview-4 1,855 1/1/2025
2.0.0-preview-3 4,551 12/9/2024
2.0.0-preview-2 1,966 11/14/2024
2.0.0-preview-1 1,140 11/10/2024
1.4.1 247,382 10/27/2024
1.4.0 323,820 9/15/2024
1.3.0 390,266 8/4/2024
1.2.0 374,109 6/2/2024
1.2.0-preview1 896 5/19/2024
1.1.0 171,010 4/24/2024
1.0.0 272,414 2/29/2024
1.0.0-preview2 4,455 2/23/2024
1.0.0-preview1 1,283 2/11/2024
0.26.0 139,589 2/11/2024
0.25.0 6,982 2/4/2024 0.25.0 is deprecated.
0.25.0-preview1 1,469 1/14/2024
0.24.0 324,911 11/12/2023
0.24.0-preview1 1,929 9/3/2023
0.23.0 370,891 8/1/2023
0.22.0 63,282 7/9/2023
0.21.0 885,849 5/28/2023
0.21.0-preview2 1,815 5/21/2023
0.21.0-preview1 1,796 5/1/2023
0.20.0 158,473 4/8/2023
0.20.0-preview2 1,668 3/29/2023
0.20.0-preview1 1,972 3/3/2023
0.19.0 168,914 2/12/2023
0.18.0 112,416 12/18/2022
0.17.0 19,031 12/4/2022
0.16.0 20,701 11/12/2022
0.15.0 226,188 10/26/2022
0.14.0 10,923 10/18/2022
0.13.0 110,478 8/14/2022
0.12.0 8,657 7/19/2022
0.11.1 2,981 7/15/2022
0.11.0 3,018 7/12/2022
0.10.0 161,550 5/1/2022
0.10.0-preview1 1,667 4/23/2022
0.9.0 69,950 2/17/2022
0.1.10-beta3 3,383 2/14/2022
0.1.10-beta2 1,687 2/11/2022
0.1.10-beta1 1,635 2/9/2022
0.1.10-alpha2 1,709 1/30/2022
0.1.10-alpha1 1,523 1/27/2022
0.1.9 52,456 11/23/2021
0.1.8 7,333 11/23/2021
0.1.7 20,113 10/16/2021
0.1.6 36,631 8/1/2021
0.1.5 5,085 6/29/2021
0.1.4 4,663 6/5/2021
0.1.3 4,244 4/3/2021
0.1.2 14,818 2/26/2021
0.1.1 2,797 1/19/2021
0.1.0 3,140 12/31/2020

- Add: Tagging support
- Add: Clear support
- Add: Microsoft HybridCache support
- Change: new AllowStaleOnReadOnly entry option for more granular control
- Perf: better serializers perf thanks to native array buffers/array pools
- Change: removed RecyclableMemoryStreamManager support from serializes (not needed anymore)
- Change: ReThrowSerializationExceptions does not affect serialization, only deserialization
- Perf: better metadata handling, with metadata-less support
- Add: support for immutable objects when using Auto-Clone
- Add: better Observability with tagging support for logs, traces and metrics
- Fix: soft-fails in a factory (eg: ctx.Fail("Oops")) is now supported for with background factory completion
- Change: better, more predictable Expire
- Change: better eager refresh handling
- Change: the auto-generated InstanceId for each cache is now shorter (saves space in logs and traces)
- Update: all [Obsolete] members has been marked as errors
- Update: package dependencies