expiry-map

A Map implementation with expirable items

MIT 5 个版本
安装
npm install expiry-map
yarn add expiry-map
pnpm add expiry-map
bun add expiry-map
README

expiry-map

CI codedov

A Map implementation with expirable items

Memory is automatically released when an item expires by removing it from the Map.

Install

$ npm install expiry-map

Usage

import ExpiryMap = require('expiry-map');

const map = new ExpiryMap(1000, [
	['unicorn', '🦄']
]);

map.get('unicorn');
//=> 🦄

map.set('rainbow', '🌈');

console.log(map.size);
//=> 2

// Wait for 1 second...
map.get('unicorn');
//=> undefined

console.log(map.size);
//=> 0

API

ExpiryMap(maxAge, [iterable])

maxAge

Type: number

Milliseconds until an item in the Map expires.

iterable

Type: Object

An Array or other iterable object whose elements are key-value pairs.

Instance

Any of the Map methods.

License

MIT © Sam Verschueren

版本列表
2.0.0 2022-02-08
1.1.0 2018-08-21
1.0.2 2018-08-15
1.0.1 2018-08-14
1.0.0 2018-08-14