Output caching with Aspire Redis
While response caching focuses on HTTP header manipulation and client-side caching, ASP.NET Core’s output caching middleware takes a fundamentally different approach. Instead of relying on browsers to store and validate cached content, the output cache stores the complete response on the server side. When combined with Redis through .NET Aspire integration, this creates a powerful distributed caching solution that works across multiple server instances.
Getting ready
This recipe requires Docker Desktop to be installed and running.
It is essential that you are always installing Aspire packages for .NET 9 not for .NET 8.
The starting project can be found here: https://github.com/PacktPublishing/ASP.NET-9-Web-API-Cookbook/tree/main/start/chapter10/OutputCacheRedis.
How to do it…
- Navigate to the
BooksAPI
project folder and install the necessary NuGet package. Open your terminal and install theAspire Redis
OutputCaching...