Skip to content

yourtion/node-ecache

Repository files navigation

NPM version build status Test coverage David deps node version npm download npm license

node-ecache

Greenkeeper badge DeepScan grade

Easy use Memory and Redis cache implementation

Install

$ npm install ecache --save

How to use

import { InMemoryCache, RedisCache, MRCache } from "ecache";
// const { InMemoryCache, RedisCache, MRCache } = require("ecache");

const inMemoryCache = new InMemoryCache({ ttl: 1 });
const redisCache = new RedisCache({ client: redis, ttl: 1 });
const mrCache = new MRCache({
  redis: { client: redis, ttl: 10 },
  memory: { ttl: 1 },
});

const cache = new InMemoryCache({ ttl: 5 });

// Set Data
await cache.set(KEY, val);
// Get Data
const res = await cache.get(KEY);
// Delete Data
await cache.delete(KEY);

// Use getData and setData
// On concurrency query just run once
cache.setData("getList", (type) => mysql.queryAsync(`SELECT * FROM list where t = "${type}"`));
const list = await cache.getData("getList");

About

Easy use Memory and Redis cache implementation

Resources

License

Stars

Watchers

Forks

Packages

No packages published