码云 IDEA 插件最新版本发布,支持 Pull Request

Yourtion / node-ecacheTypeScriptMIT

指数
0
Watch 7 Star 22 Fork 2
加入码云
与超过 300 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
简单易用的缓存系统,包括内存缓存、Redis缓存、内存+Redis两级缓存,同时提供并发控制获取数据方法 展开 收起

Loading...
README.md

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

点评 ( 1 )

你可以在登录后,发表评论

搜索帮助