Skip to content

Commit ce1f62b

Browse files
committed
Added docs for cache: no-store
1 parent 26d34a4 commit ce1f62b

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
_build:
3+
publishResources: false
4+
render: never
5+
list: never
6+
7+
name: "Enable `cache: no-store` HTTP standard API"
8+
sort_date: "2024-11-11"
9+
enabled_date: "2024-11-11"
10+
enable_flag: "cache_option_enabled"
11+
disable_flag: "cache_option_disabled"
12+
---
13+
14+
When this flag is enabled, the cache header becomes available within the [`fetch()` API](/workers/runtime-apis/fetch/). The option for `no-store` is enabled.
15+
16+
For a cross-zone request the headers `Pragma: no-cache` and `Cache-Control: no-cache` are sent to the origin.
17+
18+
For subrequests to origins not hosted by Cloudflare, `no-store` bypasses Cloudflare's cache in addition to specifying the above headers.
19+
20+
Example:
21+
22+
```js
23+
const response = await fetch("https://example.com", { cache: 'no-store'});
24+
```
25+
26+
You can also create a Response object to pass around:
27+
28+
```js
29+
const request = new Response("https://example.com", { cache: 'no-store'});
30+
const response = await fetch(request);
31+
```

src/content/docs/workers/examples/cache-using-fetch.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,15 @@ async function handleRequest(request) {
466466
```
467467
468468
</TabItem> </Tabs>
469+
470+
## Using the HTTP Cache API
471+
472+
Currently we only support the `no-store` header for controlling cache.
473+
When `no-store` is supplied the cache is bypassed both on the way to the origin and on the way back.
474+
For cross-zone requests this simply forwards the `Pragma: no-cache` and `Cache-Control: no-cache` headers to the origin.
475+
This is because the cache is on the origin side for cross-zone requests.
476+
For grey-cloud requests this bypasses the use of Cloudflare's caches.
477+
478+
```js
479+
fetch(event.request, { cache: 'no-store'});
480+
```

src/content/docs/workers/runtime-apis/request.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ let request = new Request(input, options)
6262

6363
An object containing properties that you want to apply to the request.
6464

65+
* `cache` `undefined | 'no-store'` optional
6566

67+
* Standard HTTP `cache` header. Only `cache: no-store` is supported.
6668

6769
* `cf` RequestInitCfProperties optional
6870

@@ -180,7 +182,7 @@ All properties of an incoming `Request` object (the request you receive from the
180182

181183
:::caution
182184

183-
If the response is a redirect and the redirect mode is set to `follow` (see below), then all headers will be forwarded to the redirect destination, even if the destination is a different hostname or domain. This includes sensitive headers like `Cookie`, `Authorization`, or any application-specific headers. If this is not the behavior you want, you should set redirect mode to `manual` and implement your own redirect policy. Note that redirect mode defaults to `manual` for requests that originated from the Worker's client, so this warning only applies to `fetch()`es made by a Worker that are not proxying the original request.
185+
If the response is a redirect and the redirect mode is set to `follow` (see below), then all headers will be forwarded to the redirect destination, even if the destination is a different hostname or domain. This includes sensitive headers like `Cookie`, `Authorization`, or any application-specific headers. If this is not the behavior you want, you should set redirect mode to `manual` and implement your own redirect policy. Note that redirect mode defaults to `manual` for requests that originated from the Worker's client, so this warning only applies to `fetch()`es made by a Worker that are not proxying the original request.
184186
:::
185187

186188
* `method` string read-only
@@ -410,4 +412,4 @@ Using any other type of `ReadableStream` as the body of a request will result in
410412
* [Examples: Modify request property](/workers/examples/modify-request-property/)
411413
* [Examples: Accessing the `cf` object](/workers/examples/accessing-the-cloudflare-object/)
412414
* [Reference: `Response`](/workers/runtime-apis/response/)
413-
* Write your Worker code in [ES modules syntax](/workers/reference/migrate-to-module-workers/) for an optimized experience.
415+
* Write your Worker code in [ES modules syntax](/workers/reference/migrate-to-module-workers/) for an optimized experience.

0 commit comments

Comments
 (0)