Implementing HybridCache with FusionCache v2 in .NET 9

FusionCache v2 is the very first production-ready implementation of Microsoft HybridCache, including Microsoft’s own which is currently still in preview.

It’s super easy to get started:

  • Install the NuGets …

  • Setup the FusionCache service and be sure to call AsHybridCache() …

  • Finally inject and use the service …

HybridCache read sequence flow

To ensure everything is functioning correctly, it’s crucial to understand the sequence and timing of cache-related events. This understanding helps us identify which system logs or traces to review at specific points during the process.

The sequence diagram below illustrates our caching strategy: we first check the L1 in-memory cache for the item. If it’s not found, we then query the L2 distributed cache. Only if the item is still unavailable in the distributed cache do we proceed to the persistent database for a fresh read from the master source.

Click on the image for a larger view in a new window.

Sample project shown above on GitHub

https://github.com/davepcallan/FusionCacheHybridCacheDemo

Leave a Reply

Your email address will not be published. Required fields are marked *