Class UmbracoBackOfficeCacheHeadersMiddleware
Sets the default Cache-Control response header on requests served from the cache-busted
BackOffice assets path (/umbraco/backoffice/<hash>/...).
Inheritance
Namespace: Umbraco.Cms.Web.Common.Middleware
Assembly: Umbraco.Web.Common.dll
Syntax
public class UmbracoBackOfficeCacheHeadersMiddleware
Remarks
The path prefix contains a deployment-wide hash derived from the Umbraco version
(see BackOfficeCacheBustHash). Because the URL itself
changes whenever the version changes, all responses served under that prefix are safe to mark
as immutable with a long max-age, regardless of whether the on-disk filename
contains a content hash.
In debug mode the underlying built assets may change while the app is running (typically
from a developer rebuilding the backoffice without restarting the host). The header is
therefore set to no-cache, which still allows the browser to store the response
but forces an If-None-Match revalidation on the next request — yielding fast 304s
when nothing has changed and full 200s when the file on disk has been rebuilt.
no-store would force a full re-download on every request, which is unnecessary.
This middleware is non-destructive to consumer customisation:
-
The header is only set when no
Cache-Controlvalue is already present on the response, so synchronous overrides written upstream (includingStaticFileOptions.OnPrepareResponse) take precedence. -
The header is set via
HttpResponse.OnStarting; consumer callbacks registered later in the pipeline fire first (LIFO) and can therefore override the default. - Non-2xx responses (e.g. 404) are not marked as immutable to avoid long-lived caching of error responses.
Must run before UseUmbracoBackOfficeRewrites(IApplicationBuilder) so the original request path (still containing the cache-bust hash) can be matched.
Constructors
View SourceUmbracoBackOfficeCacheHeadersMiddleware(IBackOfficePathGenerator, IHostingEnvironment)
Declaration
public UmbracoBackOfficeCacheHeadersMiddleware(IBackOfficePathGenerator backOfficePathGenerator, IHostingEnvironment hostingEnvironment)
Parameters
| Type | Name | Description |
|---|---|---|
| IBackOfficePathGenerator | backOfficePathGenerator | |
| IHostingEnvironment | hostingEnvironment |
Methods
View SourceInvokeAsync(HttpContext, RequestDelegate)
Declaration
public Task InvokeAsync(HttpContext context, RequestDelegate next)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpContext | context | |
| RequestDelegate | next |
Returns
| Type | Description |
|---|---|
| Task |