ASP.NET Core MVC Interview Question #142

What is output caching in ASP.NET Core?

Dependency Injection, Services, Error Handling, Logging & Performance Senior Advanced

Quick Interview Answer

Output caching is server-side middleware that can store and reuse generated responses according to configured policies. It provides application-controlled caching behavior and can reduce repeated work for suitable endpoints.

Detailed Explanation

Output caching is server-side middleware that can store and reuse generated responses according to configured policies. It provides application-controlled caching behavior and can reduce repeated work for suitable endpoints.

Cache policies must account for route, query, header, authentication, and personalization differences as required. Never cache private user-specific output under a key that could be reused for another user.

Code Example

builder.Services.AddOutputCache();

app.UseOutputCache();

[OutputCache(Duration = 60)]
public IActionResult Catalog()
{
    return View();
}