The Craft of Caching
Caching is a crucial optimization technique for any web application, but the variety of caching approaches can be overwhelming. This chapter starts with client-side caching strategies, where we will explore both manual HTTP header manipulation and ASP.NET Core’s ResponseCache
middleware. These initial recipes focus on putting the burden on the client. The server effectively offloads storage responsibilities to the client while maintaining control over cache validation and invalidation.
As we progress, the chapter shifts focus to server-side distributed caching using Redis. Thanks to .NET Aspire’s seamless Redis integration, implementing distributed caching becomes surprisingly straightforward. We will explore output caching middleware for simple response caching, IDistributedCache
for fine-grained control, and finally, .NET 9’s new HybridCache
. This innovative addition to the framework combines the speed of in-memory caching with the reliability...