Skip to content
0:00 / 0:00

#hybridcache#asp.netcore#redis

The New HybridCache Has a BIG Problem!

Milan Jovanović

169K subscribers • 11 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Milan Jovanović

Intermediate. Assumes working knowledge.

8.3K views1 year ago2 recommendations

Distributed systemsDatabases and dataConcurrency and parallelismSoftware architecture

Milan Jovanović explains why .NET 9's HybridCache fails to propagate cache invalidation across multiple nodes and demonstrates a Redis Pub/Sub fix.

Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt Get the source code here: patreon.com/milanjovanovic In this video, I reveal a critical issue with the newly released stable version of HybridCache library and demonstrate how to fix it. The problem occurs in multi-node environments where cache invalidation fails to propagate to all instances. What you'll learn: - Why HybridCache doesn't work properly in distributed systems - How cache invalidation only affects the current node and level 2 cache (Redis) - Step-by-step implementation of a Redis Pub/Sub solution to synchronize cache invalidation - Creating a background service to listen for cache invalidation events - Alternative solutions if you prefer not to implement this yourself I demonstrate the issue using a clear diagram showing how when one server invalidates a cache entry, the other servers' level 1 caches still contain stale data. The solution leverages Redis' publish/subscribe mechanism to broadcast invalidation messages to all application nodes. If you don't want to implement this yourself, you can either: 1. Set a very short local cache expiration time in HybridCache configuration 2. Use FusionCache as an alternative with its built-in Redis backplane support Complete with code samples and a demonstration using multiple application instances with .NET Aspire. Check out my courses: milanjovanovic.tech/courses Read my Blog here: milanjovanovic.tech/blog Join my weekly .NET newsletter: milanjovanovic.tech Chapters HybridCache: The Problem Drawing some boxes Solving the problem - Option 1 Solving the problem - Option 2 (FusionCache) Solving the problem - Option 3 (Channels)

Why it's here

2 people recommend this

What people say. Recommended as a practical guide to fixing L1 cache synchronization issues when using HybridCache in multi-node environments.

u/jespersoein r/dotnet • Recommends

On “Hybrid cache invalidate L1 cache?”

If you’re using Redis as L2, this solution works great: link to this video With other L2 systems they might have a similar broadcast functionality. If not, it shouldn’t be too hard to implement using something like MQTT.

u/Rare_Comfortable88in r/dotnet • Recommends

On “Does the new .NET 9+ HybridCache handle distributed L1 removal?”

see this one, really use full for me link to this video