File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments