1.0.2 • Published 7 years ago

tuplemap v1.0.2

Weekly downloads
1,170
License
MPL-2.0
Repository
-
Last release
7 years ago

TupleMap npm version Build Status Dependency Status Coverage Status

A Map which accepts multiple objects 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 TupleMap

This lib has no dependency, but requires a native implementation of Map.

Usage

var TupleMap = require('TupleMap');

// When the `limit` option is set, TupleMap turns into an LRU cache.
// Clearing the map every X seconds can also be an acceptable strategy sometimes.
var cache = new TupleMap({ limit: 10000 });

var keyPart1 = {};
var keyPart2 = 'yolo';
var keyPart3 = [];
var value = {any: 'thing'};

// Note that following keyPart tuples are wrapped in new arrays that are !==
// (otherwise a Map would have been enough).
cache.set([keyPart1, keyPart2, keyPart3], value);

cache.has([keyPart1, keyPart2, keyPart3]) === true;
cache.get([keyPart1, keyPart2, keyPart3]) === value;

When should you use this map?

This map should be used with functions that take more than one argument. It is a less efficient but more flexible alternative to WeakTupleMap.

Author

@louis_remi

License

MPL-2.0