Skip to content

Files

Latest commit

683931f · Feb 19, 2025

History

History

ZiggyCreatures.FusionCache

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Feb 19, 2025
Jan 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Dec 4, 2022
Feb 19, 2025
Dec 31, 2020
Jan 19, 2025
Dec 4, 2022
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 2, 2025
Feb 19, 2025
Feb 19, 2025
Jan 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Apr 8, 2023
Feb 4, 2024
Feb 19, 2025
Feb 19, 2025
Nov 12, 2023
Feb 19, 2025
Feb 19, 2025
Feb 2, 2025

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

  • 🔀 L1+L2: any implementation of IDistributedCache can be used as an optional 2nd level, all transparently
  • 📢 Backplane: in a multi-node scenario, it can notify the other nodes about changes in the cache, so all will be in-sync
  • ⏱ Soft/Hard Timeouts: a slow factory (or distributed cache) will not slow down your application, and no data will be wasted
  • 🦅 Eager Refresh: start a non-blocking background refresh before the expiration occurs
  • 🔂 Conditional Refresh: like HTTP Conditional Requests, but for caching
  • 🚀 Background Distributed Operations: distributed operations can easily be executed in the background, safely, for better performance

Flexibility

  • 📛 Named Caches: easily work with multiple named caches, even if differently configured
  • 🏷️ Tagging: tags can be associated to entries, to later expire them all at once
  • 🧼 Clear: clear an entire cache, even with shared L2, cache key prefix, etc
  • Ⓜ️ Microsoft HybridCache: can be used as an implementation of the new HybridCache abstraction from Microsoft, all while adding extra features
  • 🧙‍♂️ Adaptive Caching: for when you don't know upfront the entry options (eg: Duration), since they depends on the value being cached itself
  • 🔃 Dependency Injection + Builder: native support for Dependency Injection, with a nice fluent interface including a Builder support
  • ♊ Auto-Clone: be sure that cached values returned can be safely modified
  • 💫 Fully sync/async: native support for both the synchronous and asynchronous programming model
  • 🧩 Plugins: extend FusionCache with additional behavior like adding support for metrics, statistics, etc...

Observability

  • 🔭 OpenTelemetry: native observability support via OpenTelemetry
  • 📜 Logging: comprehensive, structured and customizable, via the standard ILogger interface
  • 📞 Events: a comprehensive set of events, both at a high level and at lower levels (memory/distributed)

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