* 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
| 16 | * - body is returned as a Readable stream instead of an array |
| 17 | */ |
| 18 | class 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 | |
| 50 | describe('cache interceptor with async store', () => { |
| 51 | test('stale-while-revalidate 304 refreshes cache with async store', async () => { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…