1.0.0 • Published 4 years ago

node-api-cache v1.0.0

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

node-api-cache

A simple tool for generate cache for node.js

Get started

Usage

const NodeApiCache = require('node-api-cache');
const cacheClient = new NodeApiCache({
  useNodeCache: true, 
  useRedis: true, 
  redisConfig: { uri: 'redis://localhost:6379' }
})

// set cache will effect both in local cache and redis
cacheClient.set('key', 'value');

// return promise as default
cacheclient.get('key').then(result => {
  console.log(result)
})

API

constructor

new NodeApiCache({
  useNodeCache,
  nodeCacheTime,
  useRedis,
  redisConfig,
  redisCacheTime
})
  • @params
  • useNodeCache: whether use local node cache;
  • nodeCacheTime: the local cache expired time (in millisecond), default is 10 minutes;
  • useRedis: whether to use redis to store your cache;
  • redisConfig: the redis configuration;
  • redisCacheTime: the redis cache expires time (in second), default is 3 hours

set

set = function(key, value)

get

get = function(key)

clearLocalCache

clearLocalCache = function()