https://github.com/tiagoguirra/cache-on-redis
  
  
    Cache on redis is a simple library to temporary storage cache using node.js and redis. 
    https://github.com/tiagoguirra/cache-on-redis
  
cache redis
        Last synced: 3 months ago 
        JSON representation
    
Cache on redis is a simple library to temporary storage cache using node.js and redis.
- Host: GitHub
- URL: https://github.com/tiagoguirra/cache-on-redis
- Owner: tiagoguirra
- Created: 2020-09-29T14:28:29.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-04T18:01:04.000Z (almost 4 years ago)
- Last Synced: 2025-06-14T16:17:48.347Z (5 months ago)
- Topics: cache, redis
- Language: TypeScript
- Homepage:
- Size: 77.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- 
            Metadata Files:
            - Readme: README.md
 
Awesome Lists containing this project
README
          # cache-on-redis
Cache on redis is a simple library to temporary storage cache using node.js and redis.
## Install
```bash
$ npm install cache-on-redis
```
## Usage
Then create a cache-on-redis instance passing redis options:
```javascript
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
```javascript
await cache.setJson('myCacheKey', {
  name: 'Redis cache',
  version: 'beta',
})
```
Create a cache from string
```javascript
await cache.set('myCacheKey', 'storage this')
```
##### Get cache value
Get a cache json object
```javascript
await cache.getJson('myCacheKey')
```
Get a cache string
```javascript
await cache.get('myCacheKey')
```
##### Invalidate
To invalidate cache
```javascript
await cache.invalidate('myCacheKey')
```
To invalidate cache using patterns
```javascript
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                              |