0.1.2 • Published 7 years ago

nano-persistent-memoizer v0.1.2

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

nano-persistent-memoizer

Memoizes a String -> String or String -> Promise String function persistently. It uses window.localStorage on the browser and the filesystem (~/.nano-persistent-memoizer) on Node. <1K compressed.

Usage

var memo = require("nano-persistent-memoizer");

var twice = memo("twice").async(str => {
  for (var i = 0; i < 10000000; ++i) {
    Math.sin(i);
  }
  return Promise.resolve(str + str);
});

(async () => {
  console.log(await twice("foo")); // slow
  console.log(await twice("bar")); // slow
  console.log(await twice("foo")); // instant (cached)
  console.log(await twice("bar")); // instant (cached)
  twice.clear(); // clears cache
})();