Key Value data store with TTL in either Redis or in-memory
import Cache from "@jolzee/cache";
// for in-memory cache
const cache = new Cache({
defaultTimeToLiveMin: 20
});
// for Redis backed cache
const cache = new Cache({
redisHost: "redis-host"
redisPort: 6379
redisPassword: "your-password"
defaultTimeToLiveMin: 20
});
//Redis alternative
const cache = new Cache({
redisUrl: "redis://user:password@redis-service.com:6379/"
defaultTimeToLiveMin: 20
});
cache.set("12345", "😁");
cache.get("12345").then(val => {
console.log(val); // 😁
});
cache.del("12345");
cache.get("12345").then(val => {
console.log(val); // null
});
cache.set("22222", "🚀", 5); // cache for 5 min not 20
// wait more than 5 min
cache.get("22222").then(val => {
console.log(val); // null
});
Install via yarn
yarn add @jolzee/cache
or npm
npm install @jolzee/cache
You can pass in extra options as a configuration object (➕ required, ➖ optional, ✏️ default).
Redis - all required
{
redisHost: "redis-host";
redisPort: 6379;
redisPassword: "your-password";
defaultTimeToLiveMin: 20;
}
In Memory - all required
{
defaultTimeToLiveMin: 20;
}
cache
is compiled as a collection of CommonJS modules & ES2015 modules for bundlers that support the jsnext:main
or module
field in package.json (Rollup, Webpack 2)
The code is available under the MIT license.
We are open to contributions, see CONTRIBUTING.md for more info.
This module was created using generator-jolzee-node-module.