1.0.0 • Published 7 years ago
namedtuplemap v1.0.0
NamedTupleMap
A Map which accepts a named tuple as a key. This lib is one of the several possible cache for memoize-immutable, but it can suit other use-cases as it implements a usual Map API.
Install
npm install --save NamedTupleMap
This lib has no dependency, but requires a native implementation of Map.
Usage
var NamedTupleMap = require('NamedTupleMap');
// When the `limit` option is set, NamedTupleMap turns into an LRU cache.
// Clearing the map every X seconds can also be an acceptable strategy sometimes.
var cache = new NamedTupleMap({ limit: 10000 });
var keyPart1 = {};
var keyPart2 = 'yolo';
var keyPart3 = [];
var value = {any: 'thing'};
// Note that following named tuples are wrapped in new objects that are !==
// (otherwise a Map would have been enough).
cache.set({
oh: keyPart1,
my: keyPart2,
goodness: keyPart3
}, value);
cache.has({
oh: keyPart1,
my: keyPart2,
goodness: keyPart3
}) === true;
cache.get({
oh: keyPart1,
my: keyPart2,
goodness: keyPart3
}) === value;
Author
License
MPL-2.0
1.0.0
7 years ago