liveBook · Manning

No-store directive

As explained in Building Web APIs with ASP.NET Core

The no-store directive is an HTTP Cache-Control directive that instructs caches not to store a response or its request.

The no-store directive tells caches not to store a response. It is useful when a response contains request-specific or sensitive information, such as error details, passwords, payment data, or personal data. section 3.1.3

In an ASP.NET Core web API, apply no-store with the [ResponseCache(NoStore = true)] attribute on an endpoint. This is clearer and easier to maintain than writing the Cache-Control header manually. section 3.1.3 section 8.2.1

Use the directive in these practical situations:

  • Disable caching for error responses whose contents are unique to a particular request. section 3.1.3
  • Add a fallback middleware policy when an endpoint does not explicitly specify a caching strategy. section 8.2.2
  • Prefer an explicit public cache with a short max-age for reusable data instead of applying no-store everywhere. section 3.1.3

Protecting API error responses

Mark Minimal API error endpoints with [ResponseCache(NoStore = true)]. For example, an /error endpoint returning Results.Problem() and an /error/test endpoint throwing an exception both prevent response caching.

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains endpoint attributes, manual headers, and fallback middleware, but does not develop cache-system internals.
Examples
Uses Minimal API error endpoints, a manual cache-control endpoint, and custom middleware setting no-cache and no-store.
What it assumes
Assumes basic ASP.NET Core endpoints and HTTP response headers while introducing ResponseCache configuration and custom middleware.
What you can do after
Apply it via ASP.NET Core ResponseCache attributes or configure a middleware fallback, then verify headers in browser development tools.
How it connects
Connects Cache-Control, HTTP caching, ResponseCache attributes, Minimal APIs, middleware, and intermediate caching.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.