Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bonniernews/exp-rediscache
A Redis caching library
https://github.com/bonniernews/exp-rediscache
Last synced: about 8 hours ago
JSON representation
A Redis caching library
- Host: GitHub
- URL: https://github.com/bonniernews/exp-rediscache
- Owner: BonnierNews
- License: mit
- Created: 2016-02-01T16:02:19.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-09-02T11:15:18.000Z (about 2 years ago)
- Last Synced: 2024-11-16T01:38:52.954Z (2 days ago)
- Language: JavaScript
- Size: 69.3 KB
- Stars: 1
- Watchers: 61
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
rediscache
==========A Redis caching library meant to be used with [exp-asynccache](https://github.com/ExpressenAB/exp-asynccache).
Usage:
```javascript
const cache = new AsyncCache(new RedisCache());const hit = cache.lookup("foo", (resolve) => {
resolve(null, "baz");
});hit.then((value) => {
console.log(value); // value will be "baz"
});
```Values cached with a maxAge uses Redis's SETEX command and sets a TTL on the key.
```javascript
const cache = new AsyncCache(new RedisCache());const hit = cache.lookup("foo", (resolve) => {
resolve(null, "baz", 1000);
});hit.then((value) => {
console.log(value); // value will be "baz"
});
```The underlying Redis client will queue up any commands if Redis is down. If you want instant errors back you can set the `enableOfflineQueue` option to `false`. This allows [exp-asynccache](https://github.com/ExpressenAB/exp-asynccache) to transparently fall back to the resolve callback in such a case.
```javascript
const cache = new AsyncCache(new RedisCache({
enableOfflineQueue: false
}));
```To namespace your cache keys (in case you run multiple apps against the same Redis), you can specify the `keyPrefix` option.
```javascript
const cache = new AsyncCache(new RedisCache({
keyPrefix: "namespace"
}));
```## Dev
For local development and running tests:
```bash
$ npm ci
$ docker-compose up // starts the local redis instance
$ npm test
```