ASP.NET Core Interview Question #186

What are Cache-Control and related HTTP caching headers?

Performance, Caching & HTTP Senior Advanced

Quick Interview Answer

HTTP caching headers communicate how clients and intermediary caches may store and reuse a response. Cache-Control directives can specify rules such as public, private, no-store, max-age, and revalidation behavior.

Detailed Explanation

HTTP caching headers communicate how clients and intermediary caches may store and reuse a response. Cache-Control directives can specify rules such as public, private, no-store, max-age, and revalidation behavior.

ETag and Last-Modified can support conditional requests so a client can ask whether previously cached content is still current.

Headers must reflect the sensitivity and variability of the response. Private or user-specific content must not accidentally be marked as publicly cacheable.

Code Example

context.Response.Headers.CacheControl =
    "public,max-age=300";

// For sensitive content:
// Cache-Control: no-store