Get unlimited public & private packages + team-based management with npm Teams.Learn more »

@omni-tools/map-age-cleaner

1.0.0-alpha.1 • Public • Published

map-age-cleaner

Npm Version Build Status codecov

Automatically cleanup expired items in a Map

📢 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 🙂

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 possible
    • property: 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 the key and value 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

Install

npm i @omni-tools/map-age-cleaner

DownloadsWeekly Downloads

3

Version

1.0.0-alpha.1

License

MIT

Unpacked Size

10.2 kB

Total Files

5

Last publish

Collaborators

  • avatar