sm
stats-map
npm i stats-map
sm

stats-map

Map that keeps track of the hits and misses

by Sam Verschueren

1.0.0 (see all)License:MITTypeScript:Not Found
npm i stats-map
Readme

stats-map Build Status

Mem cache map that keeps track of the hits and misses

Install

$ npm install --save stats-map

Usage

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}

API

StatsMap([iterable])

Inherits from Map.

.stats

Type: object

The statistics of the map like the hits and misses.

  • mem - Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input.

License

MIT © Sam Verschueren

Downloads/wk

523

GitHub Stars

16

LAST COMMIT

6yrs ago

MAINTAINERS

1

CONTRIBUTORS

0

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
1.0.0
latest
6yrs ago
No alternatives found
No tutorials found
Add a tutorial