0.0.4 • Published 4 years ago

@jolzee/cache v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

cache

Key Value data store with TTL in either Redis or in-memory

Usage

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
});

Installation

Install via yarn

yarn add @jolzee/cache

or npm

npm install @jolzee/cache

configuration

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;
}

Builds

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)

License

The code is available under the MIT license.

Contributing

We are open to contributions, see CONTRIBUTING.md for more info.

Misc

This module was created using generator-jolzee-node-module.