map-cached

0.1.3 • Public • Published

map-cached

NPM

Fully Cached interface for a Promised Map.

var MapCached = require('map-cached');
// MapCached(<source>, <set-cache>);
// source:    a promised map, like MapPg (map-pg)
// set-cache: size of set cache, flushed when full or manually
var MapPromised = require('map-promised');
var MapCached = require('map-cached');
 
var mapp = new MapPromised(new Map());
var mapc = new MapCached(mapp);
mapp.setup().then(() => {
  mapp.set('a', 1);
}).then(() => {
  return mapc.setup();
}).then(() => {
  mapc.set('b', 2);
  mapc.size;             // 2
  mapc.get('b');         // 2
  mapc.get('a');         // 1
  mapc.delete('b');
  mapc.size;             // 1
  mapc.set('c', 3);
  mapc.set('d', 4);
  mapc.size;             // 3
  mapc.flush().then(() => {
    return mapp.size;
  }).then((ans) => ans); // 3
  // ...
});

Readme

Keywords

Package Sidebar

Install

npm i map-cached

Weekly Downloads

0

Version

0.1.3

License

MIT

Last publish

Collaborators

  • wolfram77