ZiggyCreatures.FusionCache 1.0.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package ZiggyCreatures.FusionCache --version 1.0.0                
NuGet\Install-Package ZiggyCreatures.FusionCache -Version 1.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="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZiggyCreatures.FusionCache --version 1.0.0                
#r "nuget: ZiggyCreatures.FusionCache, 1.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=1.0.0

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

FusionCache

FusionCache logo

FusionCache is an easy to use, fast and robust cache with advanced resiliency features and an optional distributed 2nd level.

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've tried to put together these experiences and came up with FusionCache.

FusionCache diagram

It uses a memory cache (any impl of the standard IMemoryCache interface) as the primary backing store and optionally a distributed, 2nd level cache (any impl of the standard IDistributedCache interface) as a secondary backing store for better resilience and higher performance, for example in a multi-node scenario or to avoid the typical effects of a cold start (initial empty cache, maybe after a restart).

Optionally, it can also use a backplane: in a multi-node scenario this will send notifications to the other nodes to keep each node's memory cache perfectly synchronized, without any additional work.

FusionCache also includes some advanced resiliency features like a fail-safe mechanism, cache stampede prevention, fine grained soft/hard timeouts with background factory completion, customizable extensive logging and more (see below).

🏆 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.

More into videos? The fine folks at On .NET have been kind enough to invite me on the show and listen to me mumbling random caching stuff.

On .NET Talk

✔ Features

These are the key features of FusionCache:

⭐ Quick Start

FusionCache can be installed via the nuget UI (search for the ZiggyCreatures.FusionCache package) or via the nuget package manager console:

PM> Install-Package ZiggyCreatures.FusionCache

As an example, imagine having a method that retrieves a product from your database:

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

💡 This is using the sync programming model, but it would be equally valid with the newer async one for even better performance.

To start using FusionCache the first thing is create a cache instance:

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

If instead you are using DI (Dependency Injection) use this:

services.AddFusionCache();

We can also specify some global options, like a default FusionCacheEntryOptions object to serve as a default for each call we'll make, with a duration of 2 minutes and a Low priority:

var cache = new FusionCache(new FusionCacheOptions() {
	DefaultEntryOptions = new FusionCacheEntryOptions {
		Duration = TimeSpan.FromMinutes(2),
		Priority = CacheItemPriority.Low
	}
});

Or, using DI, like this:

services.AddFusionCache()
	.WithDefaultEntryOptions(new FusionCacheEntryOptions {
		Duration = TimeSpan.FromMinutes(2),
		Priority = CacheItemPriority.Low
	})
;

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 simply do this:

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.

đŸ’ŧ Is it Production Ready â„ĸī¸ ?

Yes!

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

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

And again, if you are using it please ✉ drop me a line, I'd like to know!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.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 (25)

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 (7)

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).
LANCommander/LANCommander
Version Downloads Last updated
1.4.1 7,575 10/27/2024
1.4.0 130,055 9/15/2024
1.3.0 177,748 8/4/2024
1.2.0 318,625 6/2/2024
1.2.0-preview1 781 5/19/2024
1.1.0 141,339 4/24/2024
1.0.0 224,843 2/29/2024
1.0.0-preview2 4,386 2/23/2024
1.0.0-preview1 1,252 2/11/2024
0.26.0 130,074 2/11/2024
0.25.0 6,781 2/4/2024 0.25.0 is deprecated.
0.25.0-preview1 1,341 1/14/2024
0.24.0 291,696 11/12/2023
0.24.0-preview1 1,919 9/3/2023
0.23.0 346,393 8/1/2023
0.22.0 49,400 7/9/2023
0.21.0 742,520 5/28/2023
0.21.0-preview2 1,804 5/21/2023
0.21.0-preview1 1,765 5/1/2023
0.20.0 152,223 4/8/2023
0.20.0-preview2 1,658 3/29/2023
0.20.0-preview1 1,962 3/3/2023
0.19.0 167,720 2/12/2023
0.18.0 111,317 12/18/2022
0.17.0 18,346 12/4/2022
0.16.0 20,138 11/12/2022
0.15.0 222,916 10/26/2022
0.14.0 10,677 10/18/2022
0.13.0 105,388 8/14/2022
0.12.0 8,586 7/19/2022
0.11.1 2,968 7/15/2022
0.11.0 2,987 7/12/2022
0.10.0 158,733 5/1/2022
0.10.0-preview1 1,640 4/23/2022
0.9.0 68,163 2/17/2022
0.1.10-beta3 3,373 2/14/2022
0.1.10-beta2 1,662 2/11/2022
0.1.10-beta1 1,625 2/9/2022
0.1.10-alpha2 1,701 1/30/2022
0.1.10-alpha1 1,513 1/27/2022
0.1.9 51,958 11/23/2021
0.1.8 7,320 11/23/2021
0.1.7 18,735 10/16/2021
0.1.6 36,458 8/1/2021
0.1.5 5,068 6/29/2021
0.1.4 4,646 6/5/2021
0.1.3 4,220 4/3/2021
0.1.2 14,790 2/26/2021
0.1.1 2,784 1/19/2021
0.1.0 2,805 12/31/2020

- Perf: zero allocations/minimal cpu usage in Get happy path
- Perf: greatly reduced allocations/cpu usage in Set happy path
- Perf: less allocations/cpu usage when not using distributed components
- Perf: less allocations/cpu usage (via closures) when using events
- Perf: zero allocations at all when not using logging (no support structures init for operationId generation)
- Perf: the distributed cache check during eager refresh is now totally non blocking
- Perf: removed the small reflection usage that was there
- Added: new IgnoreIncomingBackplaneNotifications option
- Added: incoherent cache names detection when using DI/builder
- Added: TryWithAutoSetup() in the builder now also does a TryWithRegisteredMemoryLocker()
- Changed: FusionCacheEntryOptions.Size is now nullable (long?)
- Changed: better nullability annotations for generic types
- Changed: removed the cache instance id from the metrics tags, because high cardinality
- Changed: better logging in some parts (backplane + memory locker)
- Fix: fixed a couple of typos in xml comments
- Updated: package dependencies