@neoskop/redis-promise-cache
v0.4.2
Published
Store promises and synchrone values in redis
Downloads
94
Readme
@neoskop/redis-promise-cache
Store promises and synchrone values in redis.
Prevents multiple redundant calls to the same (expensive) resource. See here for more details.
Usage
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;
}
Testing
Run tests with yarn test
. See package.json for additional test scripts.
Versioning
This package follows SemVer and uses @neoskop/flow-bump for versioning.
License
This project is licensed under the MIT License - see the LICENSE.md file for details