$ npm install --save stats-map
const StatsMap = require('./');
const mem = require('mem');
let i = 0;
const counter = () => ++i;
const cache = new StatsMap();
const memoized = mem(counter, {cache});
memoized('foo');
//=> 1
// cached as it's the same argument
memoized('foo');
//=> 1
// not cached anymore as the argument changed
memoized('bar');
//=> 2
memoized('bar');
//=> 2
console.log(cache.stats);
//=> {hits: 2, misses: 2}
Inherits from Map.
Type: object
The statistics of the map like the hits
and misses
.
MIT © Sam Verschueren
Version | Tag | Published |
---|---|---|
1.0.0 | latest | 6yrs ago |