Skip to content

Commit ba9ac65

Browse files
Added notes for cache request hostnames (#18634)
* Added two notes * Update src/content/docs/workers/runtime-apis/cache.mdx * Update src/content/docs/workers/runtime-apis/cache.mdx * update with example * Fixed * made into note, simplified code example * Update src/content/docs/workers/runtime-apis/cache.mdx Co-authored-by: Brendan Irvine-Broque <[email protected]> * Changed to recommended approach --------- Co-authored-by: Brendan Irvine-Broque <[email protected]>
1 parent 4de3672 commit ba9ac65

File tree

1 file changed

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

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,17 @@ 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+
:::note
53+
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.
54+
55+
```js
56+
// recommended approach: use your Worker hostname to ensure efficient caching
57+
request.url = "https://your-Worker-hostname.com/";
5258

59+
let myCache = await caches.open('custom:cache');
60+
let response = await myCache.match(request);
61+
```
62+
:::
5363
***
5464

5565
## Headers
@@ -105,10 +115,6 @@ cache.put(request, response);
105115

106116

107117
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-
112118
#### Parameters
113119

114120

@@ -152,10 +158,6 @@ cache.match(request, options);
152158

153159

154160
The `stale-while-revalidate` and `stale-if-error` directives are not supported when using the `cache.put` or `cache.match` methods.
155-
156-
157-
:::
158-
159161
#### Parameters
160162

161163

0 commit comments

Comments
 (0)