@inventivetalent/loading-cache
v0.7.1
Published
loading cache based on ben-manes/caffeine and node-cache
Downloads
640
Maintainers
Readme
loading-cache
Caching utility for NodeJS with loading functionality, based on ben-manes/caffeine
npm install --save @inventivetalent/loading-cache
Usage
Sync
import { Caches, Time, LoadingCache } from "@inventivetalent/loading-cache";
const cache = Caches.builder()
.expireAfterWrite(Time.minutes(10))
.expireAfterAccess(Time.minutes(5))
.build(key => Math.random() * 100);
Async
import { Caches, Time, AsyncLoadingCache } from "@inventivetalent/loading-cache";
const cache = Caches.builder()
.expireAfterWrite(Time.minutes(10))
.expireAfterAccess(Time.minutes(5))
.buildAsync(
key => new Promise(resolve => {
setTimeout(() => {
resolve(Math.random() * 100);
}, Math.random() * 10);
})
);