ASP.NET Core MVC Interview Question #141

What is response caching in ASP.NET Core MVC?

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

Quick Interview Answer

Response caching uses HTTP caching semantics to influence whether clients or intermediary caches can reuse a response. The ResponseCache attribute can set cache-related response headers for controller actions.

Detailed Explanation

Response caching uses HTTP caching semantics to influence whether clients or intermediary caches can reuse a response. The ResponseCache attribute can set cache-related response headers for controller actions.

Caching must be designed carefully for personalized or authenticated pages. A response containing user-specific or sensitive data must not be accidentally shared between users through a public cache.

Code Example

[ResponseCache(
    Duration = 60,
    Location = ResponseCacheLocation.Any)]
public IActionResult PublicCatalog()
{
    return View();
}