Skip to content

Commit 42cbc17

Browse files
committed
update with example
1 parent 8f74b36 commit 42cbc17

File tree

1 file changed

+9
-16
lines changed
  • src/content/docs/workers/runtime-apis

1 file changed

+9
-16
lines changed

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@ You may create and manage additional Cache instances via the [`caches.open`](htt
4949
let myCache = await caches.open('custom:cache');
5050
await myCache.match(request);
5151
```
52+
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.
5253

54+
```async fetch(request, env, ctx) {
55+
// avoid overriding the request URL or passing a new request into the cache API
56+
request.url = "https://some-overridden-value.com";
57+
58+
let myCache = await caches.open('custom:cache');
59+
await myCache.match(request);
60+
},
61+
```
5362
***
5463

5564
## Headers
@@ -105,14 +114,6 @@ cache.put(request, response);
105114

106115

107116
The `stale-while-revalidate` and `stale-if-error` directives are not supported when using the `cache.put` or `cache.match` methods.
108-
109-
110-
:::
111-
112-
:::note
113-
To avoid unnecessary DNS lookups and cache inefficiencies, do not override the hostname in cache requests. Always use the hostname that matches the domain associated with your Worker.
114-
:::
115-
116117
#### Parameters
117118

118119

@@ -156,14 +157,6 @@ cache.match(request, options);
156157

157158

158159
The `stale-while-revalidate` and `stale-if-error` directives are not supported when using the `cache.put` or `cache.match` methods.
159-
160-
161-
:::
162-
163-
:::note
164-
To avoid unnecessary DNS lookups and cache inefficiencies, do not override the hostname in cache requests. Always use the hostname that matches the domain associated with your Worker.
165-
:::
166-
167160
#### Parameters
168161

169162

0 commit comments

Comments
 (0)