Skip to content

Commit a8eccb7

Browse files
committed
fixup
1 parent b28d390 commit a8eccb7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/cache/memory-cache-store.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MemoryCacheStore {
2020
#size = 0
2121

2222
/**
23-
* @type {Map<string, Map<string, GetResult[]>>}
23+
* @type {Map<string, Map<string, (GetResult & { body: Buffer[] | null })[]>>}
2424
*/
2525
#map = new Map()
2626
#arr = []
@@ -158,6 +158,26 @@ class MemoryCacheStore {
158158
* @param {CacheKey} key
159159
*/
160160
delete (key) {
161+
// TODO (perf): This could be implemented more efficiently...
162+
163+
// https://www.rfc-editor.org/rfc/rfc9111.html#section-2-3
164+
const topLevelKey = `${key.origin}:${key.path}`
165+
166+
const cachedPaths = this.#map.get(topLevelKey)
167+
if (cachedPaths) {
168+
for (const values of cachedPaths.values()) {
169+
for (const value of values) {
170+
if (value.body) {
171+
for (const buf of value.body) {
172+
this.#size -= buf.byteLength
173+
}
174+
value.body = null
175+
}
176+
}
177+
}
178+
this.#arr = this.#arr.filter(value => value.body != null)
179+
}
180+
161181
this.#map.delete(`${key.origin}:${key.path}`)
162182
}
163183

0 commit comments

Comments
 (0)