- Cache module extending the native Map class.
- I wrote this because someone in a Discord server had no idea how to. I don't personally use this code and it may (expect it to) be un-maintained.
- Cache(s) retain all methods that Maps have.
- This does not override or modify
Map
in any way.
const Cash = require('cash');
const Cache = new Cash(/* Map options */);
Finds the index of a given key.
Similar to Array.indexOf
.
Cache.index('key');
Returns an array of the cache's keys.
Cache.keyArray();
Returns an array of the cache's values.
Better than <Map>.values
because it doesn't involve Iterators.
Cache.valueArray();
Sets multiple entries at once.
Cache.setAll({ acceptNull: true }, ['k', 'v'], ['k2', 'v2']);
Concat two caches (or concat a Map to Cache).
const map = new Map();
map.set('a', 'b');
map.set('c', 'd');
Cache.concat(map);
Cache.concat('string'); // error
Convert to valid JSON that can be saved or read from.
It can also be parsed using Cache.parse()
.
Cache.stringify();
Convert JSON string to a Map object.
Cache.parse();
// convert back to Cache
const cache = new Cash(Cache.parse('{ "JSON": "string" }'));
Alias for Map.size
.