Skip to content

VictorTaelin/nano-persistent-memoizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
})();

About

Caches a function permanently on browser and node.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published