NoCacheMiddleware Class
Ensures responses are marked as non-cacheable when no Cache-Control header is already set.
public sealed class NoCacheMiddlewareRemarks
Register this middleware after any component that serves cacheable content, such as UseStaticFiles: the static file middleware sets ETag and Last-Modified but no Cache-Control, so an earlier registration marks every static asset as non-cacheable.
Because the default includes no-store, responses defaulted by this middleware are not stored by UseResponseCaching, UseOutputCache or a CDN. Responses that set their own Cache-Control are never modified.
Constructors
| Name | Description |
|---|---|
| NoCacheMiddleware(RequestDelegate) | Ensures responses are marked as non-cacheable when no Cache-Control header is already set. |
NoCacheMiddleware(RequestDelegate)
NoCacheMiddleware.csEnsures responses are marked as non-cacheable when no Cache-Control header is already set.
public NoCacheMiddleware(RequestDelegate next)Parameters
nextRequestDelegate- The next middleware in the pipeline.
Remarks
Register this middleware after any component that serves cacheable content, such as UseStaticFiles: the static file middleware sets ETag and Last-Modified but no Cache-Control, so an earlier registration marks every static asset as non-cacheable.
Because the default includes no-store, responses defaulted by this middleware are not stored by UseResponseCaching, UseOutputCache or a CDN. Responses that set their own Cache-Control are never modified.
Methods
| Name | Description |
|---|---|
| InvokeAsync(HttpContext) | Processes the request and adds a default non-cacheable Cache-Control header to the response when none is set. |
InvokeAsync(HttpContext)
NoCacheMiddleware.csProcesses the request and adds a default non-cacheable Cache-Control header to the response when none is set.
net10.0
public Task InvokeAsync(HttpContext context)net11.0
public Task InvokeAsync(HttpContext context)Parameters
contextHttpContext- The current HTTP context.
Returns
Task A task that completes when the middleware has finished processing.