Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 27 days 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 (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-04T18:01:04.000Z (about 3 years ago)
- Last Synced: 2024-12-01T17:28:18.054Z (about 1 month 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 |