Output Caching in .NET 8 — A Pragmatic Guide
Output Caching in ASP.NET Core lets an application reuse complete HTTP responses for requests whose results do not need to be generated again every time.
This can reduce repeated application work, database access and other expensive operations for public or semi-static endpoints.
When to Use It
Output caching is useful for endpoints where the same response can be safely reused, such as public pages, catalog data, reference information or reports that do not change on every request.
Basic Configuration
// Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOutputCache();
var app = builder.Build();
app.UseOutputCache();
app.MapGet("/products", async (MyDbContext db) =>
{
return await db.Products.ToListAsync();
})
.CacheOutput(p =>
p.Expire(TimeSpan.FromSeconds(60)));
Output Caching vs. Response Caching
Output Caching is controlled by server-side policies. Response Caching, by contrast, follows HTTP caching semantics and request and response headers.
This distinction gives the application more direct control over which responses are cached and for how long.
Cache Storage
By default, cached output is stored in the application process. For applications running across multiple instances, ASP.NET Core can use Redis as a shared Output Cache store.
Redis support is available through the
Microsoft.AspNetCore.OutputCaching.StackExchangeRedis
package and AddStackExchangeRedisOutputCache().
Practical Considerations
- Cache only responses that are safe to reuse.
- Choose expiration times according to how frequently the data changes.
- Avoid caching personalized responses without an appropriate policy.
- Monitor hit rates and response times instead of assuming a fixed performance gain.
Key Takeaway
Output Caching is a relatively simple way to reduce repeated work in ASP.NET Core applications. The important part is defining clear cache policies and measuring their effect under real traffic.
5 min read • Published Nov 10, 2025
Back to Writing