npm.io
0.0.9 • Published 4 years ago

cache-on-redis

Licence
ISC
Version
0.0.9
Deps
1
Size
13 kB
Vulns
0
Weekly
0

cache-on-redis

Cache on redis is a simple library to temporary storage cache using node.js and redis.

Install

$ npm install cache-on-redis

Usage

Then create a cache-on-redis instance passing redis options:

const { CacheOnRedis } = require('cache-on-redis')
const cache = new CacheOnRedis({
  host: 'localhost',
  port: 6379,
  connect_timeout: 3600000,
  retry_strategy: (options) => {
    return 2000
  },
})
Set cache value

Create a cache from json object

await cache.setJson('myCacheKey', {
  name: 'Redis cache',
  version: 'beta',
})

Create a cache from string

await cache.set('myCacheKey', 'storage this')
Get cache value

Get a cache json object

await cache.getJson('myCacheKey')

Get a cache string

await cache.get('myCacheKey')
Invalidate

To invalidate cache

await cache.invalidate('myCacheKey')

To invalidate cache using patterns

await cache.invalidate('myCa*', true)
options object properties

The cache instance acceps a options argument:

  • CacheOnRedis(redisInstance,options)
Property Default Description
key_prefix cache Cache key prefix, every cache storage will contain this prefix
expire_time 3600 Cache expiration time in secconds

Keywords