# cache-on-redis

> A simple redis cache library

Latest version **0.0.9** (published 2022-01-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install cache-on-redis
pnpm add cache-on-redis
yarn add cache-on-redis
bun add cache-on-redis
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2022-01-04 |
| First published | 2020-09-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tiago Guirra |
| Maintainers | guirra |
| Keywords | redis, cache, cache json |

## Links

- npm: https://www.npmjs.com/package/cache-on-redis
- Repository: https://github.com/tiagoguirra/cache-on-redis
- npm.io page: https://npm.io/package/cache-on-redis

## Dependencies (1)

- [redis](https://npm.io/package/redis.md) ^3.0.2

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.0.9 (latest) — 2022-01-04
- 0.0.8 — 2022-01-04
- 0.0.7 — 2020-11-04
- 0.0.6 — 2020-11-04
- 0.0.5 — 2020-11-04
- 0.0.4 — 2020-09-29
- 0.0.3 — 2020-09-29
- 0.0.2 — 2020-09-29
- 0.0.1 — 2020-09-29

## 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                              |

---
_Source: https://npm.io/package/cache-on-redis · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
