File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,21 @@ export class BasicCache {
9393 evict ( item ) {
9494 return new BasicCache ( this . cache . remove ( item ) )
9595 }
96+
97+ /**
98+ * Removes entry from cache
99+ * @param {Iterable } items
100+ * @return {BasicCache }
101+ */
102+ evictMany ( items ) {
103+ const newCache = this . cache . withMutations ( c => {
104+ items . forEach ( item => {
105+ c . remove ( item )
106+ } )
107+ } )
108+
109+ return new BasicCache ( newCache )
110+ }
96111}
97112
98113const DEFAULT_LRU_LIMIT = 1000
@@ -173,15 +188,12 @@ export class LRUCache {
173188 )
174189 }
175190
176- const cache = ( this . lru
177- . take ( this . evictCount )
178- . reduce ( ( c , evictItem ) => c . evict ( evictItem ) , this . cache )
179- . miss ( item , entry ) )
191+ const itemsToRemove = this . lru . take ( this . evictCount )
180192
181193 lruCache = new LRUCache (
182194 this . limit ,
183195 this . evictCount ,
184- cache ,
196+ this . cache . evictMany ( itemsToRemove ) . miss ( item , entry ) ,
185197 this . lru . skip ( this . evictCount ) . add ( item )
186198 )
187199 } else {
You can’t perform that action at this time.
0 commit comments