This article explains how to set Cache-Control directives like public, private, and no-cache, use cache profiles, and implement cache busting for static assets to improve performance.
Scenario: A Studio Optimizes Its Static Site
As an illustration, picture a small studio author crafting a static informational site built from plain HTML files and a shared stylesheet. The material at hand is a folder of pages, a versioned stylesheet filename such as studio-main-2024-06.css, and a short asset manifest. The author drafts three header lines for a plain-text configuration file, each tied to a distinct file pattern rather than a single page.
The first candidate is a broad rule for stylesheets and fonts, written as Cache-Control: public, max-age=31536000, immutable. The reasoning is that the versioned filename already carries change information, so the header can declare permanence without the author editing headers on every edit. The second rule targets HTML documents, written as Cache-Control: no-cache, which asks caches to revalidate before serving. The third covers a rarely updated image directory, written as Cache-Control: public, max-age=86400, so images refresh daily. The author records each rule next to its matching path in the manifest, then pairs the versioned stylesheet with a rename step so old filenames retire cleanly.
For the static page itself, the author sketches two short example records to test how fields fit. A candidate record named About page uses the path /about/, the content type text/html, and the header value no-cache. A second record named Hero illustration uses the path /img/hero.webp, the content type image/webp, and the value public, max-age=86400. A third record, Site stylesheet, uses /assets/studio-main-2024-06.css with text/css and public, max-age=31536000, immutable. Placing these three records side by side makes the central trade-off visible: the stylesheet favors long reuse, while the HTML page favors fresh revalidation. The author chooses this split because editing the About page should appear immediately, whereas the stylesheet rarely changes and its filename changes when it does. The image sits between them, refreshed daily.
These records and filenames are self-made examples for explaining the problem, not a record of any existing site, prior setup, or tested outcome. The author treats them as a working sketch, keeping the header values beside the paths so later edits stay in one place.
Understanding Public, Private, and No-Cache Directives
Microsoft's ASP.NET Core response caching documentation defines the common Cache-Control directives this way: public means a cache may store the response, while private means shared caches must not store it, though a private cache may store and reuse it. For no-cache, the documentation distinguishes request and response meanings. On a request, the cache cannot use a stored response to satisfy it and the origin server regenerates the response; on a response, the response must not be used for later requests without validation by the origin server.1
The same documentation maps location options to header values. Location.Any becomes Cache-Control public, indicating the client or any intermediate proxy may cache the value, including the response caching middleware. Location.Client becomes private, indicating only the client may cache the value and intermediate caches should not. Setting Location to None sets Cache-Control and Pragma to no-cache, and with NoStore true the Cache-Control value becomes no-store,no-cache.1
You can start with the versioned stylesheet you already have and decide which of the three directives fits each file pattern you actually own. Take your draft header lines and rewrite each one next to the matching filename, so the choice becomes concrete. For the stylesheet named studio-main-2024-06.css, a public directive with a long max-age reads naturally because the filename can change; you might note in your manifest that the version stamp is what makes the long lifetime safe. For a page such as /about/ that you may still edit, you could try a no-cache directive and write the line as a question to yourself: does this page need revalidation before reuse? For anything you consider internal or account-specific, a private directive marks the boundary; you can record that decision in the same manifest row.
A small comparison table you fill in yourself keeps the choices visible. Use columns like file pattern, draft directive, reason, and review trigger. One filled example row might read: pattern studio-main-*.css, directive public with a long max-age, reason the versioned name changes on edits, review trigger when naming conventions change. A second row for /about/ could read: directive no-cache, reason the page text is still being revised, review trigger once the text stabilizes. These rows are your own working notes, not evidence of any prior configuration.
You can then reread the three lines together and check that each directive matches the pattern it sits beside, since a public rule copied onto an editable page would contradict the reason you wrote. If a row's reason no longer fits, you might revise the directive or the filename rather than leaving both in place.
Using Cache Profiles for Consistent Configuration
In ASP.NET Core, cache profiles are configured as options so that the same response cache settings do not have to be repeated across multiple controller action attributes. The page shows a profile registered with the name Default30 and a Duration of 30 seconds, added through CacheProfiles in the MVC options.1
An attribute then references that profile by name, and the values found in the referenced profile serve as defaults. Any property specified directly on the attribute overrides the corresponding value from the profile. The page states that the Default30 profile produces the response header with public and max-age=30.1
The attribute can be applied to Razor Pages, MVC controllers, and MVC action methods. On Razor Pages, the attribute cannot be applied to handler methods. For MVC action methods, a method-level attribute overrides settings specified in a class-level attribute.1
You can turn those three draft lines into a reusable cache profile by grouping file patterns that should always share the same directive, then naming the group in your own notes. For the stylesheet example, the profile might be called long-lived assets and hold the pattern for files ending in a version stamp, with a short note that the name changes whenever the file changes. The static pages themselves could sit in a second profile, such as short-lived documents, even if the directive you draft for them is identical, because the review reason differs.
Your draft notes can stay deliberately simple. For each profile, write the group name, the file patterns it covers, the directive line you are considering, and the condition that should prompt you to revisit it. One filled example might read: profile, long-lived assets; patterns, the versioned stylesheet file; draft line, public with a one-year maximum age; revisit when the filename version changes. A second example could read: profile, short-lived documents; patterns, the plain HTML pages; draft line, public with a brief maximum age; revisit when page copy changes.
You might keep a third placeholder profile for anything you have not yet sorted, rather than forcing an early decision. Before adding a new file to the folder, you can check which profile it belongs to and whether its filename carries a version. If it does not, the placeholder is where it waits until you choose. This keeps the configuration readable and lets you compare drafts side by side.
Implementing Cache Busting for Static Assets
For static assets, MDN describes adding a version or hash to the filename or query string as the cache-busting pattern, so a numbered library version or an image hash gives updated content a new URL. With the content no longer changing at a given URL, the example uses Cache-Control: max-age=31536000, immutable for the assets path; immutable tells a cache the response will not be updated while fresh and avoids unnecessary conditional requests on reload.2
To make clients pick up a new HTML response and the new asset versions, the example sets Cache-Control: no-cache on the HTML file itself, which allows storing but requires revalidation before reuse. MDN also notes that if the HTML is behind Basic or Digest Authentication, files under the assets path are not stored in a shared cache unless public, s-maxage, or must-revalidate is also present.2
You can take the versioned stylesheet filename you already have and write a short busting note beside it, recording which part of the name will change and which parts stay fixed. For studio-main-2024-06.css, you might mark the studio-main stem as stable and the date segment as the changing part, then note that the new file will be referenced from the pages that use it. That note is your own planning material, not evidence that a rename has happened.
When you prepare the next filename, consider advancing only the date segment, for example to studio-main-2024-09.css, and keep the stem identical. Then list the pages that point to the stylesheet and mark each one you intend to update, so the change is visible before you touch any file.
If your stylesheet is imported by another file, you might add a second note naming that importer and recording whether its own reference also needs the new filename. A small table could hold columns like asset, current filename, next filename, pages to update, and open question. One filled row might read: shared stylesheet, studio-main-2024-06.css, studio-main-2024-09.css, home and about, confirm no page still copies the old name inline.
You can choose to leave the old file in place until every listed page is checked, and decide later whether to keep or remove it.
Handling Conflicting Cache Directives
When directives conflict, the source says the most restrictive directive should in theory be honored. It gives a combined header of private, no-cache, no-store, max-age=0 and must-revalidate as an example that is essentially meaningless because the other directives conflict with no-store, treating that line as equivalent to no-store alone. The same page distinguishes no-cache from no-store: no-cache allows storage but requires validation before reuse, while no-store is the directive for preventing storage. It also notes that s-maxage and must-revalidate each unlock the shared-cache restriction on responses to requests carrying an Authorization header, so public is not needed in that case.2
When you draft your header lines, you can check for conflicts by writing each directive next to the file pattern it targets and asking whether the two could ever disagree. For example, you might note that a broad public, max-age rule for stylesheets should not sit on the same pattern as a no-cache rule for editable pages. Consider reading the lines as pairs and marking any pattern that appears twice with different directives.
A simple self-recorded comparison can help you decide. You might list each file pattern, the directive you are considering, and where the directive came from, such as a copied line from an earlier setup. One filled row could read stylesheet pattern, public with a long max-age, copied from an older version. Another could read page pattern, no-cache, drafted this round. You can then pick which row to keep for each pattern and note the reason in a nearby column.
You might also check how a profile covers the same file more than once. If a grouped rule and a single-file rule both touch your stylesheet, consider choosing one as the authority and writing that choice beside the profile name. Preparing this now, before you apply headers, keeps the final set easier to reread and adjust.
Verifying Header Behavior Against RFC Standards
RFC 9111 defines the header fields that control cache behavior, so the draft lines can be checked against the standard itself rather than a local rule of thumb. Under its storage requirements, a cache must not store a response unless the response contains at least one of a public response directive, a private directive where the cache is not shared, an Expires header field, a max-age response directive, an s-maxage directive where the cache is shared, a cache extension allowing storage, or a status code defined as heuristically cacheable.3
The same section notes that a cache extension can override those listed requirements, so the presence of a qualifying directive is the stated condition, not a guarantee about how every cache will behave. A cache must reuse a stored response only when the presented target URI matches, the request method associated with the stored response allows it, and the nominated request header fields match, among other conditions.3
Take the three draft header lines you already wrote and, beside each one, copy the exact directive text you intend to publish. You might read each line slowly and ask a plain question: does the directive name still mean what your note claims it means? A line you labeled as forbidding storage deserves a second look if the directive you actually wrote merely requires revalidation. You can mark that mismatch in the margin rather than fixing it immediately, so the full set of questions stays visible.
A short verification sheet you fill in yourself can keep this checkable. Use columns such as file pattern, directive as written, meaning you intended, and one sentence naming the reader behavior you expect. One filled row might read: stylesheet pattern, public max-age with immutable, intended long-lived reuse, expected to skip a repeat request on a revisit. A second row could cover the page itself, with a directive that permits storage but asks for revalidation, and a note saying the reader should confirm freshness before reuse.
Consider adding a third row for any directive that combines several tokens, then rephrasing the combination in ordinary words. If the rephrasing contradicts your intended meaning, that is your signal to revise the draft before it goes near a configuration file. You can decide which rows need rewriting and which already match.
Frequently asked questions
What columns can I use in a small comparison table to keep my cache directive choices visible?
A small comparison table you fill in yourself keeps the choices visible. Use columns like file pattern, draft directive, reason, and review trigger.
What should I write for each cache profile in my draft notes?
Your draft notes can stay deliberately simple. For each profile, write the group name, the file patterns it covers, the directive line you are considering, and the condition that should prompt you to revisit it.
How can I record which part of a versioned stylesheet filename changes and which stays fixed?
You can take the versioned stylesheet filename you already have and write a short busting note beside it, recording which part of the name will change and which parts stay fixed. For studio-main-2024-06.css, you might mark the studio-main stem as stable and the date segment as the changing part, then note that the new file will be referenced from the pages that use it.
ASP.NET Core 中的响应缓存 | Microsoft Learn . Retrieved 2026-11-21. ↩︎ ↩︎ ↩︎ ↩︎ ↩︎
Cache-Control header - HTTP | MDN . Retrieved 2026-11-21. ↩︎ ↩︎ ↩︎
RFC 9111: HTTP Caching . Retrieved 2026-11-21. ↩︎ ↩︎