ASP.NET Core's output cache stores finished HTTP responses, not endpoint results, so one missing key dimension can serve another user's data. Benjamin Abt walks through key composition, middleware ordering, tag eviction and when Redis is worth the cost.
Key points
- The stored unit is the finished HTTP response: status code, most headers and exact body bytes.
- The default policy stores only anonymous GET/HEAD 200s without Authorization or Set-Cookie headers.
- The base key covers method, scheme, host, path and query; Accept-Language is not added automatically.
- With no duration configured, entries expire after 60 seconds and some framework headers are excluded.
- Locking is per process, and the Redis provider needs IOutputCacheStore, not IDistributedCache.
- The .NET 11 preview adds IOutputCachePolicyProvider so policy sets can come from a provider.
Why it matters
Output caching looks like a one-line win and turns into a correctness problem weeks later, once a personalized endpoint ends up behind it. Teams that already run a distributed data cache assume this layer behaves the same way; it does not, and the store's own semantics matter.
Before enabling it on an existing API, list which routes are truly anonymous and repeatable, keep personalized responses out, and measure on a single replica before adding Redis with its failure mode. The policy provider arriving in .NET 11 is worth watching, but the boundary you draw is the real win.
Real-world use
- A public catalog endpoint that varies by category and language and needs a small, bounded key space
- A multi-replica API that needs shared entries and tag invalidation through Redis
- A personalized endpoint that must re-check authorization every request, better served by HybridCache below the endpoint
- File downloads and SSE or gRPC streams that do not belong in the output cache at all
This summary was generated by the agent from the original post on Benjamin Abt. The full text and all rights belong to its author and publisher. Go to original