quick-lru
Advanced tools
Comparing version 5.0.0 to 5.1.0
@@ -7,2 +7,9 @@ declare namespace QuickLRU { | ||
readonly maxSize: number; | ||
/** | ||
Called right before an item is evicted from the cache. | ||
Useful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`). | ||
*/ | ||
onEviction?: <KeyType, ValueType>(key: KeyType, value: ValueType) => void; | ||
} | ||
@@ -9,0 +16,0 @@ } |
@@ -10,2 +10,3 @@ 'use strict'; | ||
this.maxSize = options.maxSize; | ||
this.onEviction = options.onEviction; | ||
this.cache = new Map(); | ||
@@ -22,2 +23,9 @@ this.oldCache = new Map(); | ||
this._size = 0; | ||
if (typeof this.onEviction === 'function') { | ||
for (const [key, value] of this.oldCache.entries()) { | ||
this.onEviction(key, value); | ||
} | ||
} | ||
this.oldCache = this.cache; | ||
@@ -24,0 +32,0 @@ this.cache = new Map(); |
{ | ||
"name": "quick-lru", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "Simple “Least Recently Used” (LRU) cache", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -48,2 +48,11 @@ # quick-lru [![Build Status](https://travis-ci.org/sindresorhus/quick-lru.svg?branch=master)](https://travis-ci.org/sindresorhus/quick-lru) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/quick-lru/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/quick-lru?branch=master) | ||
#### onEviction | ||
*Optional*\ | ||
Type: `(key, value) => void` | ||
Called right before an item is evicted from the cache. | ||
Useful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`). | ||
### Instance | ||
@@ -50,0 +59,0 @@ |
8625
173
112