Multi Key Cache
A JavaScript (JS) cache that can have multiple complex values as keys. Keys can be objects, arrays, arrays-within-objects, objects-within-arrays, maps, sets, anything. Highly performant. Made for the browser and nodejs.
Install
npm install multi-key-cache --save
Use
Supports the following methods:
set(keys, val) : Sets a value to a set of keys. Keys can be an array of values, an arguments structure, or any object with a `length` property and numerical property names.get(keys) : Returns the value of a set of keys.has(keys) : Returns true if the set of keys have a value, otherwise false.delete(keys) : Deletes the value of a set of keys. values() : Returns array of all values.keyNodes() : Returns array of all individual key nodes (not sets of keys).
Examples:
var MultiKeyCache = ;var multiKeyCache = ; multiKeyCache; // sets 'my value' to keys a b cmultiKeyCache; // sets 'another value' to keys a b d multiKeyCache; // returns 'my value'multiKeyCache; // returns 'another value'multiKeyCache; // returns undefined multiKeyCache; // returns truemultiKeyCache; // deletes 'my value'multiKeyCache; // returns falsemultiKeyCache; // returns undefined
Complex objects as keys:
var MultiKeyCache = multiKeyCache = arg1 = a: 1 arg2 = b: 2 arg3 = c: d: 3 ; multiKeyCache; // sets 'my value' to complex keysmultiKeyCache; // sets 'another value' to completely unrelated set of complex keys multiKeyCache; // returns 'my value'multiKeyCache; // returns 'another value', keys container doesn't have to be an array multiKeyCache; // deletes 'my value' and associated empty keysmultiKeyCache; // returns falsemultiKeyCache; // returns undefined
Test
npm run test
License
Released under an MIT license.