Skip to content

Commit 88a1410

Browse files
authored
[Workers] Fix formatting (#21946)
1 parent 8f14248 commit 88a1410

File tree

1 file changed

+8
-39
lines changed
  • src/content/docs/workers/runtime-apis

1 file changed

+8
-39
lines changed

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

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ The Cache API is available globally but the contents of the cache do not replica
1414

1515
:::caution[Tiered caching]
1616

17-
1817
The `cache.put` method is not compatible with tiered caching. Refer to [Cache API](/workers/reference/how-the-cache-works/#cache-api) for more information. To perform tiered caching, use the [fetch API](/workers/reference/how-the-cache-works/#interact-with-the-cloudflare-cache).
1918

20-
2119
:::
2220

2321
Workers deployed to custom domains have access to functional `cache` operations. So do [Pages functions](/pages/functions/), whether attached to custom domains or `*.pages.dev` domains.
@@ -26,10 +24,8 @@ However, any Cache API operations in the Cloudflare Workers dashboard editor and
2624

2725
:::note
2826

29-
3027
This individualized zone cache object differs from Cloudflare’s Global CDN. For details, refer to [How the cache works](/workers/reference/how-the-cache-works/).
3128

32-
3329
:::
3430

3531
***
@@ -49,7 +45,9 @@ You may create and manage additional Cache instances via the [`caches.open`](htt
4945
let myCache = await caches.open('custom:cache');
5046
await myCache.match(request);
5147
```
48+
5249
:::note
50+
5351
When using the cache API, avoid overriding the hostname in cache requests, as this can lead to unnecessary DNS lookups and cache inefficiencies. Always use the hostname that matches the domain associated with your Worker.
5452

5553
```js
@@ -59,15 +57,15 @@ request.url = "https://your-Worker-hostname.com/";
5957
let myCache = await caches.open('custom:cache');
6058
let response = await myCache.match(request);
6159
```
60+
6261
:::
62+
6363
***
6464

6565
## Headers
6666

6767
Our implementation of the Cache API respects the following HTTP headers on the response passed to `put()`:
6868

69-
70-
7169
* `Cache-Control`
7270
* Controls caching directives. This is consistent with [Cloudflare Cache-Control Directives](/cache/concepts/cache-control#cache-control-directives). Refer to [Edge TTL](/cache/how-to/configure-cache-status-code#edge-ttl) for a list of HTTP response codes and their TTL when `Cache-Control` directives are not present.
7371
* `Cache-Tag`
@@ -79,18 +77,14 @@ Our implementation of the Cache API respects the following HTTP headers on the r
7977
* `Last-Modified`
8078
* Allows `cache.match()` to evaluate conditional requests with `If-Modified-Since`.
8179

82-
83-
8480
This differs from the web browser Cache API as they do not honor any headers on the request or response.
8581

8682
:::note
8783

88-
8984
Responses with `Set-Cookie` headers are never cached, because this sometimes indicates that the response contains unique data. To store a response with a `Set-Cookie` header, either delete that header or set `Cache-Control: private=Set-Cookie` on the response before calling `cache.put()`.
9085

9186
Use the `Cache-Control` method to store the response without the `Set-Cookie` header.
9287

93-
9488
:::
9589

9690
***
@@ -103,21 +97,17 @@ Use the `Cache-Control` method to store the response without the `Set-Cookie` he
10397
cache.put(request, response);
10498
```
10599

106-
107-
108100
* <code>put(request, response)</code> : Promise
109101

110102
* Attempts to add a response to the cache, using the given request as the key. Returns a promise that resolves to `undefined` regardless of whether the cache successfully stored the response.
111103

112-
113-
114104
:::note
115105

116-
117106
The `stale-while-revalidate` and `stale-if-error` directives are not supported when using the `cache.put` or `cache.match` methods.
118-
#### Parameters
119107

108+
:::
120109

110+
#### Parameters
121111

122112
* `request` string | Request
123113

@@ -126,8 +116,6 @@ The `stale-while-revalidate` and `stale-if-error` directives are not supported w
126116
* `response` Response
127117
* A [`Response`](/workers/runtime-apis/response/) object to store under the given key.
128118

129-
130-
131119
#### Invalid parameters
132120

133121
`cache.put` will throw an error if:
@@ -146,21 +134,17 @@ The `stale-while-revalidate` and `stale-if-error` directives are not supported w
146134
cache.match(request, options);
147135
```
148136

149-
150-
151137
* <code>match(request, options)</code> : Promise`<Response | undefined>`
152138

153139
* Returns a promise wrapping the response object keyed to that request.
154140

155-
156-
157141
:::note
158142

159-
160143
The `stale-while-revalidate` and `stale-if-error` directives are not supported when using the `cache.put` or `cache.match` methods.
161-
#### Parameters
144+
:::
162145

163146

147+
#### Parameters
164148

165149
* `request` string | Request
166150

@@ -169,14 +153,10 @@ The `stale-while-revalidate` and `stale-if-error` directives are not supported w
169153
* `options`
170154
* Can contain one possible property: `ignoreMethod` (Boolean). When `true`, the request is considered to be a `GET` request regardless of its actual value.
171155

172-
173-
174156
Unlike the browser Cache API, Cloudflare Workers do not support the `ignoreSearch` or `ignoreVary` options on `match()`. You can accomplish this behavior by removing query strings or HTTP headers at `put()` time.
175157

176158
Our implementation of the Cache API respects the following HTTP headers on the request passed to `match()`:
177159

178-
179-
180160
* `Range`
181161

182162
* Results in a `206` response if a matching response with a Content-Length header is found. Your Cloudflare cache always respects range requests, even if an `Accept-Ranges` header is on the response.
@@ -193,7 +173,6 @@ Our implementation of the Cache API respects the following HTTP headers on the r
193173
* Never sends a subrequest to the origin. If no matching response is found in cache, the promise that `cache.match()` returns is fulfilled with `undefined`.
194174

195175

196-
197176
#### Errors
198177

199178
`cache.match` generates a `504` error response when the requested content is missing or expired. The Cache API does not expose this `504` directly to the Worker script, instead returning `undefined`. Nevertheless, the underlying `504` is still visible in Cloudflare Logs.
@@ -206,38 +185,28 @@ If you use Cloudflare Logs, you may see these `504` responses with the `RequestS
206185
cache.delete(request, options);
207186
```
208187

209-
210-
211188
* <code>delete(request, options)</code> : Promise`<boolean>`
212189

213-
214-
215190
Deletes the `Response` object from the cache and returns a `Promise` for a Boolean response:
216191

217192
* `true`: The response was cached but is now deleted
218193
* `false`: The response was not in the cache at the time of deletion.
219194

220195
:::caution[Global purges]
221196

222-
223197
The `cache.delete` method only purges content of the cache in the data center that the Worker was invoked. For global purges, refer to [Purging assets stored with the Cache API](/workers/reference/how-the-cache-works/#purge-assets-stored-with-the-cache-api).
224198

225-
226199
:::
227200

228201
#### Parameters
229202

230-
231-
232203
* `request` string | Request
233204

234205
* The string or [`Request`](/workers/runtime-apis/request/) object used as the lookup key. Strings are interpreted as the URL for a new `Request` object.
235206

236207
* `options` object
237208
* Can contain one possible property: `ignoreMethod` (Boolean). Consider the request method a GET regardless of its actual value.
238209

239-
240-
241210
***
242211

243212
## Related resources

0 commit comments

Comments
 (0)