DEV Community

Abhishek Dave
Abhishek Dave

Posted on • Originally published at blog.ssojet.com on

Introducing HybridCache: Enhancing Cache Management for ASP.NET Core in .NET 9

The .NET Team has released HybridCache, a new library for .NET 9, available through the Microsoft.Extensions.Caching.Hybrid package. This library is designed to enhance data storage and retrieval performance by integrating both in-memory and distributed caches, such as Redis. This dual approach aims to ensure optimal performance and security for applications, regardless of their scale or complexity.

Features of HybridCache

HybridCache simplifies common development tasks by reducing boilerplate code associated with object serialization, cache-aside pattern implementation, and data consistency management. It is particularly beneficial for ASP.NET Core applications that require complex data queries, operate in microservice architectures, or need real-time data processing. Key features include:

  • Compatibility with cache backends like Redis, SQL Server, CosmosDB, and Garnet.
  • A straightforward API for ease of use.
  • Cache-stampede protection to prevent performance degradation during high traffic.
  • Cache invalidation using tags, allowing for bulk management of cache items.
  • Support for newer APIs, such as IBufferDistributedCache.
  • Flexible serialization options, including JSON and Protobuf.
  • Secure data handling and authentication by default.

Cache-Stampede Protection

Cache stampede occurs when multiple clients simultaneously request the same data after it has expired from the cache, leading to redundant computations and database queries. HybridCache addresses this issue by ensuring that when multiple requests arrive for the same data, only one computation is performed. The result is then shared with all queued requests, thereby reducing unnecessary load and maintaining data consistency.

Cache Invalidation with Tags

HybridCache allows developers to assign one or more tags to cache items, which simplifies the process of managing and invalidating cached data. Instead of deleting individual entries, developers can now delete all items with a specific tag or a set of tags in one API call. This capability enhances efficiency, especially when handling large volumes of cached data.

Compatibility and Extensibility

HybridCache is compatible with older .NET runtimes, including .NET Framework 4.7.2 and .NET Standard 2.0, making it accessible to a wide range of developers. The library includes a concrete implementation of the HybridCache abstract class which can be provided through dependency injection. Developers have the freedom to create custom implementations tailored to their specific use cases.

For more details, you can explore the HybridCache Documentation.

Current Status of HybridCache

As of now, despite .NET 9 being generally available, HybridCache is still in preview. The documentation explicitly states that it will be fully released after .NET 9.0 in a future minor release of .NET Extensions. For further inquiries, you can view the discussion on GitHub.

For enterprises looking to implement secure Single Sign-On (SSO) and user management, SSOJet offers an API-first platform featuring directory sync, SAML, OIDC, and magic link authentication. Explore our services at SSOJet to enhance your authentication strategy.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please show some love ❤️ or share a kind word in the comments if you found this useful!

Got it!