source: node_modules/undici/docs/api/CacheStorage.md

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1# CacheStorage
2
3Undici exposes a W3C spec-compliant implementation of [CacheStorage](https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage) and [Cache](https://developer.mozilla.org/en-US/docs/Web/API/Cache).
4
5## Opening a Cache
6
7Undici exports a top-level CacheStorage instance. You can open a new Cache, or duplicate a Cache with an existing name, by using `CacheStorage.prototype.open`. If you open a Cache with the same name as an already-existing Cache, its list of cached Responses will be shared between both instances.
8
9```mjs
10import { caches } from 'undici'
11
12const cache_1 = await caches.open('v1')
13const cache_2 = await caches.open('v1')
14
15// Although .open() creates a new instance,
16assert(cache_1 !== cache_2)
17// The same Response is matched in both.
18assert.deepStrictEqual(await cache_1.match('/req'), await cache_2.match('/req'))
19```
20
21## Deleting a Cache
22
23If a Cache is deleted, the cached Responses/Requests can still be used.
24
25```mjs
26const response = await cache_1.match('/req')
27await caches.delete('v1')
28
29await response.text() // the Response's body
30```
Note: See TracBrowser for help on using the repository browser.