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 {
93
93
evict ( item ) {
94
94
return new BasicCache ( this . cache . remove ( item ) )
95
95
}
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
+ }
96
111
}
97
112
98
113
const DEFAULT_LRU_LIMIT = 1000
@@ -173,15 +188,12 @@ export class LRUCache {
173
188
)
174
189
}
175
190
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 )
180
192
181
193
lruCache = new LRUCache (
182
194
this . limit ,
183
195
this . evictCount ,
184
- cache ,
196
+ this . cache . evictMany ( itemsToRemove ) . miss ( item , entry ) ,
185
197
this . lru . skip ( this . evictCount ) . add ( item )
186
198
)
187
199
} else {
You can’t perform that action at this time.
0 commit comments