0.0.9 • Published 2 years ago

cache-on-redis v0.0.9

Weekly downloads
3
License
ISC
Repository
github
Last release
2 years ago

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)
PropertyDefaultDescription
key_prefixcacheCache key prefix, every cache storage will contain this prefix
expire_time3600Cache expiration time in secconds
0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago