ASP.NET Core Web API Interview Question #134

What is response caching?

Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability Senior Advanced

Quick Interview Answer

Response caching stores and reuses HTTP responses according to HTTP caching semantics and cache headers. It is most suitable for responses that can safely be reused for equivalent requests.

Detailed Explanation

Response caching stores and reuses HTTP responses according to HTTP caching semantics and cache headers. It is most suitable for responses that can safely be reused for equivalent requests.

Authenticated, user-specific, or rapidly changing responses require careful cache rules. Incorrect caching can expose one user's data to another or return stale information.

Code Example

[ResponseCache(Duration = 60, Location = ResponseCacheLocation.Any)]
[HttpGet("catalog")]
public IActionResult Catalog()
{
    return Ok(_service.GetPublicCatalog());
}