ASP.NET Core Interview Question #184
What is output caching in ASP.NET Core?
Performance, Caching & HTTP Senior Advanced
Quick Interview Answer
Output caching stores complete HTTP responses on the server and can serve a cached response for later matching requests without executing the full endpoint again.
Detailed Explanation
Output caching stores complete HTTP responses on the server and can serve a cached response for later matching requests without executing the full endpoint again.
ASP.NET Core output caching supports policies that control expiration, variation, and which endpoints are cacheable. It is useful for responses that are expensive to generate and safe to reuse.
Personalized or security-sensitive responses require careful policies to prevent one user's content from being served to another.
Code Example
builder.Services.AddOutputCache();
var app = builder.Build();
app.UseOutputCache();
app.MapGet("/catalog", GetCatalog)
.CacheOutput(policy =>
policy.Expire(TimeSpan.FromMinutes(2)));