savvy-cache
v1.2.1
Published
A very lightweight and savvy cache utility.
Downloads
1
Readme
savvy-cache
Keyless mode
import savvy from "savvy-cache";
// doSomething function does not require a key
const doSomething = () => "did something";
// secondsUntilRefresh will refresh cache between calls to cache.get
const secondsUntilRefresh = 60;
const cache = savvy(doSomething, secondsUntilRefresh);
async function run() {
const value = await cache.get();
console.log(`Whoo savvy-cache ${value}!`);
}
Key mode
import savvy from "savvy-cache";
// doSomething example with a key
const doSomething = (key) => `did something with ${key}`;
// when secondsUntilRefresh is not provided, cache will never be refreshed
const cache = savvy(doSomething);
async function run() {
const value = await cache.get("id");
console.log(`Whoo savvy-cache ${value}!`);
}