0.0.14 • Published 7 years ago

map-cachedfifo v0.0.14

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

map-cachedfifo

NPM

FIFO Cached interface for a Promised Map.

var MapCachedFifo = require('map-cachedfifo');
// MapCachedFifo(<source>, [<cache>], [<evict>])
// source: a promised map, like MapPg (map-pg)
// cache:  size of get and set cache, evicts and flushes when full (default 1024)
// evict:  fraction of get cache to evict when full (default 0.5)
var MapPromised = require('map-promised');
var MapCachedFifo = require('map-cachedfifo');

var mapp = new MapPromised(new Map());
var mapc = new MapCachedFifo(mapp);
mapp.setup().then(() => {
  mapp.set('a', 1);
}).then(() => {
  // MapCachedFifo has no setup()
  mapc._num;                        // number of pairs in cache
  mapc._map;                        // cached items
  mapc._map.size;                   // number of items in cache, including deleted pairs
  mapc.set('b', 2);
  mapc.size.then((ans) => ans);     // 2
  mapc.get('b').then((ans) => ans); // 2
  mapc.get('a').then((ans) => ans); // 1
  mapc.delete('b');
  mapc.size.then((ans) => ans);     // 1
  mapc.set('c', 3);
  mapc.set('d', 4);
  mapc._num                         // <=2
  mapc.size.then((ans) => ans);     // 3
  mapc.flush().then(() => {
    return mapp.size;
  }).then((ans) => ans);            // 3
  // ...
});
0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago