README
map-age-cleaner
Automatically cleanup expired items in a Map
:loudspeaker: This is a fork of @SamVerschueren map-age-cleaner
, to be used for @omni-tools/mem
So far its still kind of experiment, but It might end up to be merged :slightly_smiling_face:
Install
$ npm install @omni-tools/map-age-cleaner
Usage
import mapAgeCleaner from '@omni-tools/map-age-cleaner';
const map = new Map([
['unicorn', {data: '🦄', maxAge: Date.now() + 1000}]
]);
mapAgeCleaner(map);
map.has('unicorn'); //=> true
// Wait for 1 second... 😴
map.has('unicorn'); //=> false
API
mapAgeCleaner(map, [options={property?,onExpire?}])
Returns the Map
instance.
map
: Map instance which should be cleaned up. (Type:Map
)options
: object containing eventualy the two options possibleproperty
: Name of the property which olds the expiry timestamp. (Type:string
, Default:maxAge
)onExpire
: Handler to be called with expired object on expiration. (Type:(key, value) => void
, Default:undefined
) takes thekey
andvalue
of expired item as argument
Related
- expiry-map - A
Map
implementation with expirable items - expiry-set - A
Set
implementation with expirable keys - mem - Memoize functions
License
MIT © Sam Verschueren