0.4.2 • Published 2 years ago

@neoskop/redis-promise-cache v0.4.2

Weekly downloads
23
License
MIT
Repository
github
Last release
2 years ago

@neoskop/redis-promise-cache

Build Coverage

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

0.4.2

2 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago