Store promises and synchrone values in redis.
Prevents multiple redundant calls to the same (expensive) resource. See here for more details.
import { RedisPromiseCache } from '@neoskop/redis-promise-cache'
const cache = new RedisPromiseCache({ resourceTag: 'db' });
const db : any;
/**
* with helper method
*/
async function getResource(id : string) {
return cache.getResource(id, () => db.get(id));
}
/**
* with "low level" api
*/
async function getResource2(id : string) {
const cacheEntry = cache.get(id);
if(cacheEntry) {
return cacheEntry;
}
const promise = db.get(id);
cache.set(id, promise);
return promise;
}
Run tests with yarn test
. See package.json for additional test scripts.
This package follows SemVer and uses @neoskop/flow-bump for versioning.
This project is licensed under the MIT License - see the LICENSE.md file for details