npm.io
1.0.2 • Published 5 years ago

map-expire

Licence
ISC
Version
1.0.2
Deps
0
Size
7 kB
Vulns
0
Weekly
0
Stars
6

map-expire

Extended Map object with capacity and expire features

install

npm install --save map-expire

usage


const cache = require('map-expire');

cache.set(key, value, duration)

const value = cache.get(key)
cache.delete(key)

or

const MapExpire = require('map-expire/MapExpire');
const options = {
	capacity: 100, 
	duration: 1000 // in millisecond, default expiration time
}
const cache = new MapExpire([], options)

cache.set(key, value, duration)
const value = cache.get(key)
cache.delete(key)

API

  • set(key, value, duration)

    duration will be set to default value if not given.

  • get(key) returns with undefined if not exists or expired

test

npm test

Keywords