MCPcopy
hub / github.com/nodejs/undici / AsyncCacheStore

Class AsyncCacheStore

test/interceptors/cache-async-store.js:18–48  ·  view source on GitHub ↗

* Wraps a MemoryCacheStore to simulate an async remote store: * - get() always returns a Promise * - body is returned as a Readable stream instead of an array

Source from the content-addressed store, hash-verified

16 * - body is returned as a Readable stream instead of an array
17 */
18class AsyncCacheStore {
19 #inner
20
21 constructor () {
22 this.#inner = new MemoryCacheStore()
23 }
24
25 async get (key) {
26 const result = this.#inner.get(key)
27 if (!result) return undefined
28
29 const { body, ...rest } = result
30 const readable = new Readable({ read () {} })
31 if (body) {
32 for (const chunk of body) {
33 readable.push(chunk)
34 }
35 }
36 readable.push(null)
37
38 return { ...rest, body: readable }
39 }
40
41 createWriteStream (key, value) {
42 return this.#inner.createWriteStream(key, value)
43 }
44
45 delete (key) {
46 return this.#inner.delete(key)
47 }
48}
49
50describe('cache interceptor with async store', () => {
51 test('stale-while-revalidate 304 refreshes cache with async store', async () => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…