You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
12
+
cache](/workers/reference/how-the-cache-works/) to revalidate its contents with the origin when
13
13
making subrequests from [Cloudflare Workers](/workers).
14
14
15
15
<TypeScriptExamplefilename="index.ts">
@@ -24,14 +24,17 @@ export default {
24
24
```
25
25
</TypeScriptExample>
26
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
27
+
When `no-cache` is set, the Worker request will first look for a match in Cloudflare's cache, then:
28
+
29
+
- If there is a match, a conditional request is sent to the origin, regardless of whether or not the match is fresh or stale. If the resource has not changed, the
30
+
cached version is returned. If the resource has changed, it will be downloaded from the origin, updated in the cache, and returned.
31
+
- If there is no match, Workers will make a standard request to the origin and cache the response.
29
32
30
33
This increases compatibility with NPM packages and JavaScript frameworks that rely on setting the
31
34
[`cache`](/workers/runtime-apis/request/#options) property, which is a cross-platform standard part
32
35
of the [`Request`](/workers/runtime-apis/request/) interface. Previously, if you set the `cache`
33
36
property on `Request` to `'no-cache'`, the Workers runtime threw an exception.
34
37
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
38
+
- Learn [how the Cache works with Cloudflare Workers](/workers/reference/how-the-cache-works/)
39
+
- Enable [Node.js compatibility](/workers/runtime-apis/nodejs/) for your Cloudflare Worker
40
+
- Explore [Runtime APIs](/workers/runtime-apis/) and [Bindings](/workers/runtime-apis/bindings/) available in Cloudflare Workers
Copy file name to clipboardExpand all lines: src/content/compatibility-flags/cache-no-cache.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,13 @@ When `no-cache` is specified:
20
20
- All requests have the headers `Pragma: no-cache` and `Cache-Control: no-cache` are set on them.
21
21
22
22
- Subrequests to origins not hosted by Cloudflare force Cloudflare's cache to revalidate with the
23
-
origin.
23
+
origin.
24
+
25
+
Revalidating with the origin means that the Worker request will first look for a match in Cloudflare's cache, then:
26
+
27
+
- If there is a match, a conditional request is sent to the origin, regardless of whether or not the match is fresh or stale. If the resource has not changed, the
28
+
cached version is returned. If the resource has changed, it will be downloaded from the origin, updated in the cache, and returned.
29
+
- If there is no match, Workers will make a standard request to the origin and cache the response.
24
30
25
31
Examples using `cache: 'no-cache'`:
26
32
@@ -33,4 +39,4 @@ The cache value can also be set on a `Request` object.
0 commit comments