Skip to content

Commit 876c107

Browse files
authored
feat: Add docs for cache: no-cache support release (#24245)
* feat: Add docs for cache: no-cache support release
1 parent b44cca9 commit 876c107

File tree

5 files changed

+86
-8
lines changed

5 files changed

+86
-8
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: Requests made from Cloudflare Workers can now force a revalidation of their cache with the origin.
3+
description: New runtime APIs allow you to control when subrequests revalidate cache, increasing compatibility with popular NPM packages
4+
products:
5+
- workers
6+
date: 2025-08-07
7+
---
8+
9+
import { Render, PackageManagers, TypeScriptExample } from "~/components"
10+
11+
By setting the value of the `cache` property to `no-cache`, you can force [Cloudflare's
12+
cache](/workers/reference/how-the-cache-works/) to revalidate, its contents with the origin when
13+
making subrequests from [Cloudflare Workers](/workers).
14+
15+
<TypeScriptExample filename="index.ts">
16+
```ts
17+
export default {
18+
async fetch(req, env, ctx): Promise<Response> {
19+
const request = new Request("https://cloudflare.com", { cache: 'no-cache'});
20+
const response = await fetch(request);
21+
return response;
22+
}
23+
} satisfies ExportedHandler<Environment>
24+
```
25+
</TypeScriptExample>
26+
27+
When you set the value to `no-cache` on a subrequest made from a Worker, the Cloudflare Workers
28+
runtime will force the cache to revalidate its data with the origin
29+
30+
This increases compatibility with NPM packages and JavaScript frameworks that rely on setting the
31+
[`cache`](/workers/runtime-apis/request/#options) property, which is a cross-platform standard part
32+
of the [`Request`](/workers/runtime-apis/request/) interface. Previously, if you set the `cache`
33+
property on `Request` to `'no-cache'`, the Workers runtime threw an exception.
34+
35+
* Learn [how the Cache works with Cloudflare Workers](/workers/reference/how-the-cache-works/)
36+
* Enable [Node.js compatibility](/workers/runtime-apis/nodejs/) for your Cloudflare Worker
37+
* Explore [Runtime APIs](/workers/runtime-apis/) and [Bindings](/workers/runtime-apis/bindings/) available in Cloudflare Workers
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: "Enable `cache: no-cache` HTTP standard API"
3+
sort_date: "2025-08-07"
4+
enable_date: "2025-08-07"
5+
enable_flag: "cache_no_cache_enabled"
6+
disable_flag: "cache_no_cache_disabled"
7+
---
8+
9+
When you enable the `cache_no_cache_enabled` compatibility flag, you can specify the `no-cache`
10+
value for the `cache` property of the Request interface. When this compatibility flag is not
11+
enabled, or `cache_option_disabled` is set, the Workers runtime will throw a `TypeError` saying
12+
`Unsupported cache mode: no-cache`.
13+
14+
When this flag is enabled you can instruct Cloudflare to force its cache to revalidate the
15+
response from a subrequest you make from your Worker using the [`fetch()`
16+
API](/workers/runtime-apis/fetch/):
17+
18+
When `no-cache` is specified:
19+
20+
- All requests have the headers `Pragma: no-cache` and `Cache-Control: no-cache` are set on them.
21+
22+
- Subrequests to origins not hosted by Cloudflare force Cloudflare's cache to revalidate with the
23+
origin.
24+
25+
Examples using `cache: 'no-cache'`:
26+
27+
```js
28+
const response = await fetch("https://example.com", { cache: "no-cache" });
29+
```
30+
31+
The cache value can also be set on a `Request` object.
32+
33+
```js
34+
const request = new Request("https://example.com", { cache: "no-cache" });
35+
const response = await fetch(request);
36+
```

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,12 @@ async function handleRequest(request) {
554554
## Using the HTTP Cache API
555555
556556
The `cache` mode can be set in `fetch` options.
557-
Currently Workers only support the `no-store` mode for controlling the cache.
557+
Currently Workers only support the `no-store` and `no-cache` mode for controlling the cache.
558558
When `no-store` is supplied the cache is bypassed on the way to the origin and the request is not cacheable.
559+
When `no-cache` is supplied the cache is forced to revalidate the currently cached response with the
560+
origin.
559561
560562
```js
561563
fetch(request, { cache: 'no-store'});
564+
fetch(request, { cache: 'no-cache'});
562565
```

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ async def on_scheduled(controller, env, ctx):
8080
- [`resource`](https://developer.mozilla.org/en-US/docs/Web/API/fetch#resource) Request | string | URL
8181

8282
- `options` options
83-
- `cache` `undefined | 'no-store'` optional
84-
- Standard HTTP `cache` header. Only `cache: 'no-store'` is supported.
83+
- `cache` `undefined | 'no-store' | 'no-cache'` optional
84+
- Standard HTTP `cache` header. Only `cache: 'no-store'` and `cache: 'no-cache'` are supported.
8585
Any other `cache` header will result in a `TypeError` with the message `Unsupported cache mode: <attempted-cache-mode>`.
8686
_ For all requests this forwards the `Pragma: no-cache` and `Cache-Control: no-cache` headers to the origin.
87-
_ For requests to origins not hosted by Cloudflare, `no-store` bypasses the use of Cloudflare's caches.
87+
_ For `no-store`, requests to origins not hosted by Cloudflare bypass the use of Cloudflare's caches.
88+
_ For `no-cache`, requests to origins not hosted by Cloudflare are forced to revalidate with
89+
the origin before resonding.
8890
- An object that defines the content and behavior of the request.
8991

9092
---
@@ -132,4 +134,4 @@ export default {
132134
- [Example: Fetch HTML](/workers/examples/fetch-html/)
133135
- [Example: Fetch JSON](/workers/examples/fetch-json/)
134136
- [Example: cache using Fetch](/workers/examples/cache-using-fetch/)
135-
- Write your Worker code in [ES modules syntax](/workers/reference/migrate-to-module-workers/) for an optimized experience.
137+
- Write your Worker code in [ES modules syntax](/workers/reference/migrate-to-module-workers/) for an optimized experience.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +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
65+
* `cache` `undefined | 'no-store' | 'no-cache'` optional
6666

67-
* Standard HTTP `cache` header. Only `cache: 'no-store'` is supported.
67+
* Standard HTTP `cache` header. Only `cache: 'no-store'` and `cache: 'no-cache'` are supported.
6868
Any other cache header will result in a `TypeError` with the message `Unsupported cache mode: <attempted-cache-mode>`.
6969

7070
* `cf` RequestInitCfProperties optional
@@ -432,4 +432,4 @@ Using any other type of `ReadableStream` as the body of a request will result in
432432
* [Examples: Modify request property](/workers/examples/modify-request-property/)
433433
* [Examples: Accessing the `cf` object](/workers/examples/accessing-the-cloudflare-object/)
434434
* [Reference: `Response`](/workers/runtime-apis/response/)
435-
* Write your Worker code in [ES modules syntax](/workers/reference/migrate-to-module-workers/) for an optimized experience.
435+
* Write your Worker code in [ES modules syntax](/workers/reference/migrate-to-module-workers/) for an optimized experience.

0 commit comments

Comments
 (0)