Skip to content

Commit 6495199

Browse files
Adds section about no-cahe and no-store directives (#21783)
1 parent 3dd73d7 commit 6495199

File tree

2 files changed

+32
-124
lines changed

2 files changed

+32
-124
lines changed

src/content/docs/cache/concepts/cache-control.mdx

Lines changed: 13 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -101,130 +101,19 @@ The following section covers the directives and behavioral conditions associated
101101

102102
The table below lists directives and their behaviors when Origin Cache Control is disabled and when it is enabled.
103103

104-
<table>
105-
<tbody>
106-
<th colspan="5" rowspan="1">
107-
Directive
108-
</th>
109-
<th colspan="5" rowspan="1">
110-
Origin Cache Control disabled behavior
111-
</th>
112-
<th colspan="5" rowspan="1">
113-
Origin Cache Control enabled behavior
114-
</th>
115-
<tr>
116-
<td colspan="5" rowspan="1">
117-
<code>s-maxage=0</code>
118-
</td>
119-
<td colspan="5" rowspan="1">
120-
Will not cache.
121-
</td>
122-
<td colspan="5" rowspan="1">
123-
Caches and always revalidates
124-
</td>
125-
</tr>
126-
<tr>
127-
<td colspan="5" rowspan="1">
128-
<code>max-age=0</code>
129-
</td>
130-
<td colspan="5" rowspan="1">
131-
Will not cache.
132-
</td>
133-
<td colspan="5" rowspan="1">
134-
Caches and always revalidates.
135-
</td>
136-
</tr>
137-
<tr>
138-
<td colspan="5" rowspan="1">
139-
<code>no-cache</code>
140-
</td>
141-
<td colspan="5" rowspan="1">
142-
Will not cache.
143-
</td>
144-
<td colspan="5" rowspan="1">
145-
Caches and always revalidates. Does not serve stale.
146-
</td>
147-
</tr>
148-
<tr>
149-
<td colspan="5" rowspan="1">
150-
<code>no-cache=&lt;headers&gt;</code>
151-
</td>
152-
<td colspan="5" rowspan="1">
153-
Will not cache.
154-
</td>
155-
<td colspan="5" rowspan="1">
156-
Caches if headers mentioned in <code>no-cache=&lt;headers&gt;</code> do not exist. Always
157-
revalidates if any header mentioned in <code>no-cache=&lt;headers&gt;</code> is present.
158-
</td>
159-
</tr>
160-
<tr>
161-
<td colspan="5" rowspan="1">
162-
<code>Private=&lt;headers&gt;</code>
163-
</td>
164-
<td colspan="5" rowspan="1">
165-
Will not cache.
166-
</td>
167-
<td colspan="5" rowspan="1">
168-
Does not cache <code>&lt;headers&gt;</code> values mentioned in <code>Private=&lt;headers&gt;</code> directive.
169-
</td>
170-
</tr>
171-
<tr>
172-
<td colspan="5" rowspan="1">
173-
<code>must-revalidate</code>
174-
</td>
175-
<td colspan="5" rowspan="1">
176-
Cache directive is ignored and stale is served.
177-
</td>
178-
<td colspan="5" rowspan="1">
179-
Does not serve stale. Must revalidate for CDN and for browser.
180-
</td>
181-
</tr>
182-
<tr>
183-
<td colspan="5" rowspan="1">
184-
<code>proxy-revalidate</code>
185-
</td>
186-
<td colspan="5" rowspan="1">
187-
Cache directive is ignored and stale is served.
188-
</td>
189-
<td colspan="5" rowspan="1">
190-
Does not serve stale. Must revalidate for CDN but not for browser.
191-
</td>
192-
</tr>
193-
<tr>
194-
<td colspan="5" rowspan="1">
195-
<code>no-transform</code>
196-
</td>
197-
<td colspan="5" rowspan="1">
198-
May (un)Gzip, Polish, email filter, etc.
199-
</td>
200-
<td colspan="5" rowspan="1">
201-
Does not transform body.
202-
</td>
203-
</tr>
204-
<tr>
205-
<td colspan="5" rowspan="1">
206-
<code>s-maxage=delta, delta>1</code>
207-
</td>
208-
<td colspan="5" rowspan="1">
209-
Same as <code>max-age</code>.
210-
</td>
211-
<td colspan="5" rowspan="1">
212-
<code>Max-age</code> and <code>proxy-revalidate</code>.
213-
</td>
214-
</tr>
215-
<tr>
216-
<td colspan="5" rowspan="1">
217-
<code>immutable</code>
218-
</td>
219-
<td colspan="5" rowspan="1">
220-
Not proxied downstream.
221-
</td>
222-
<td colspan="5" rowspan="1">
223-
Proxied downstream. Browser facing, does not impact caching proxies.
224-
</td>
225-
</tr>
226-
</tbody>
227-
</table>
104+
| Directive | Origin Cache Control Disabled Behavior | Origin Cache Control Enabled Behavior |
105+
|---------------------------|---------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
106+
| `s-maxage=0` | Will not cache. | Caches and always revalidates |
107+
| `max-age=0` | Will not cache. | Caches and always revalidates. |
108+
| `no-cache` | Will not cache. | Caches and always revalidates. Does not serve stale. |
109+
| `no-cache=<headers>` | Will not cache. | Caches if headers mentioned in `no-cache=<headers>` do not exist. Always revalidates if any header mentioned in `no-cache=<headers>` is present.|
110+
| `Private=<headers>` | Will not cache. | Does not cache `<headers>` values mentioned in `Private=<headers>` directive. |
111+
| `must-revalidate` | Cache directive is ignored and stale is served. | Does not serve stale. Must revalidate for CDN and for browser. |
112+
| `proxy-revalidate` | Cache directive is ignored and stale is served. | Does not serve stale. Must revalidate for CDN but not for browser. |
113+
| `no-transform` | May (un)Gzip, Polish, email filter, etc. | Does not transform body. |
114+
| `s-maxage=delta, delta>1` | Same as `max-age`. | `Max-age` and `proxy-revalidate`. |
115+
| `immutable` | Not proxied downstream. | Proxied downstream. Browser facing, does not impact caching proxies. |
116+
| `no-store` | Will not cache. | Wil not cache. |
228117

229118
### Conditions
230119

src/content/docs/cache/concepts/cdn-cache-control.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,22 @@ Behavior in response to 5XX error:
149149
</tr>
150150
</tbody>
151151
</table>
152+
153+
## Understand `no-store` and `no-cache` directives
154+
155+
There is often confusion between the directives `Cache-Control: no-store` and `Cache-Control: no-cache`, particularly regarding how they impact browser caching and features like the [Back-Forward Cache](https://developer.mozilla.org/en-US/docs/Glossary/bfcache) (BFCache).
156+
157+
### `no-store`
158+
159+
- Tells both browsers and intermediaries (like CDNs) not to store a copy of the response under any circumstance.
160+
- The response is never written to disk or memory, which means the browser must fetch it again every time.
161+
- In many browsers, `no-store` disables BFCache, because restoring a page from BFCache requires the browser to keep a copy of the page's memory state, which contradicts the “do not store” directive.
162+
- This directive is used for highly sensitive or dynamic data (for example, banking apps, personal information, secure dashboards).
163+
164+
### `no-cache`
165+
166+
- Allows storing of the response (in both browser and intermediate caches), but requires revalidation with the origin server before using it.
167+
- This ensures the content is always up-to-date, while still potentially allowing BFCache or other forms of performance optimization.
168+
- This directive is used for data that changes frequently but is not sensitive, and can be served faster if validated rather than re-downloaded.
169+
170+
For more information about how these directives behave when Origin Cache Control is enabled or disabled refer to the [Directives](/cache/concepts/cache-control/#directives) section.

0 commit comments

Comments
 (0)