ecache
TypeScript icon, indicating that this package has built-in type declarations

0.7.2 • Public • Published

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

Package Sidebar

Install

npm i ecache

Weekly Downloads

3

Version

0.7.2

License

MIT

Unpacked Size

20.8 kB

Total Files

15

Last publish

Collaborators

  • yourtion