1.0.1 • Published 8 years ago

mem-map v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

mem-map Build Status

Map to be used with mem

Please note that this is not a ponyfill for Map. Although it will use the native Map implementation if available. If Map is not available, a very lightweight Map is offerred which only implements get, set and has. This is just enough so it can be used with mem if you want to support older Node versions.

Install

$ npm install --save mem-map

Usage

const Map = require('mem-map');
const mem = require('mem');

let i = 0;
const counter = () => ++i;

const memoized = mem(counter, {cache: new Map()});

memoized('foo');
//=> 1

// cached as it's the same arguments
memoized('foo');
//=> 1

// not cached anymore as the arguments changed
memoized('bar');
//=> 2

memoized('bar');
//=> 2

License

MIT © Sam Verschueren