dryboard
v0.2.2
Published
Dryboard is an async, future-enabled memory key store.
Downloads
5
Readme
dryboard
Dryboard is an async, future-enabled memory key store.
Installation
using NPM
npm install dryboard --saveusing Yarn
yarn add dryboardUsage
Trivial
const dryboard = require("dryboard").configureDryboard();
dryboard.set("pi", "3.14159265");
const pi = await dryboard.get("pi"); //Without await, this returns a Promise so
console.log(pi); // 3.14159265 this would be a Promise if you don't use awaitLess Trivial
const dryboard = require("dryboard").configureDryboard();
setTimeout(() => dryboard.set("pi", "3.14159265"), 3000);
const pi = await dryboard.get("pi"); // waits until resolved
console.log(pi); // 3.14159265Slightly Less Trivial
const dryboard = require("dryboard").configureDryboard();
const allFetches = fetchAllItemsAndDependencies();
Promise.all(
allFetches.map(promise =>
promise.then(item => dryboard.set(item.id, item)).then(async item => ({
...item,
parent: await dryboard.get(item.parentId)
}))
)
);API
configureDryboard(preExistingValues = {})
Returns a new dryboard instance.
preExistingValues is an object that will provide initial values.
gets will be resolved immediately if found in this object.
dryboard.get(key, fallbackValue)
Returns a promise to the value of key in the cache.
If key is undefined, this method will return the fallbackValue.
dryboard.set(key, value)
Resolves the promise to the value of key in the cache.
License
MIT © Jason Santos
