# mongoose-redis-caching

> A simple caching solution for Mongoose working with Redis.

Latest version **1.13.2** (published 2022-11-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongoose-redis-caching
pnpm add mongoose-redis-caching
yarn add mongoose-redis-caching
bun add mongoose-redis-caching
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.13.2 |
| Published | 2022-11-08 |
| First published | 2018-12-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 40.9 KB |
| Known vulnerabilities | 0 (+11 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Pedre Viljoen |
| Maintainers | pedreviljoen |
| Keywords | mongoose-redis-caching, redis caching, mongoose caching, mongoose, caching, redis |

## Links

- npm: https://www.npmjs.com/package/mongoose-redis-caching
- Repository: https://github.com/pedreviljoen/mongoose-redis-caching
- Homepage: https://github.com/pedreviljoen/mongoose-redis-caching#readme
- Issues: https://github.com/pedreviljoen/mongoose-redis-caching/issues
- npm.io page: https://npm.io/package/mongoose-redis-caching

## Dependencies (3)

- [redis](https://npm.io/package/redis.md) 3.1.1
- [dotenv](https://npm.io/package/dotenv.md) 8.2.0
- [mongoose](https://npm.io/package/mongoose.md) 5.13.14

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

- 1.13.2 (latest) — 2022-11-08
- 1.13.1 — 2021-08-27
- 1.13.0 — 2021-04-26
- 1.11.9 — 2020-08-31
- 1.11.8 — 2020-08-31
- 1.11.7 — 2020-04-05
- 1.11.5 — 2020-03-05
- 1.11.3 — 2020-02-20
- 1.11.2 — 2020-02-11
- 1.11.0 — 2019-12-04
- 1.10.1 — 2019-11-23
- 1.10.0 — 2019-11-09
- 1.8.2 — 2019-10-17
- 1.8.1 — 2019-10-17
- 1.8.0 — 2019-10-11
- … 39 more at https://npm.io/package/mongoose-redis-caching/versions

## README

<div align="center">
    <img src="./assets/redis-logo.png" width="50%" height="75%">
</div>

# mongoose-redis-caching

> Simple and efficient mongoose redis caching solution

[![Package version](https://img.shields.io/npm/v/mongoose-redis-caching.svg?style=flat-square)](https://npmjs.org/package/mongoose-redis-caching)
[![License](https://img.shields.io/npm/l/mongoose-redis-caching.svg?style=flat-square)](https://github.com/pedreviljoen/mongoose-redis-caching/blob/master/LICENSE)
[![npm downloads](https://img.shields.io/npm/dm/mongoose-redis-caching.svg?style=flat-square)](https://npmjs.org/package/mongoose-redis-caching)
[![CircleCI](https://circleci.com/gh/pedreviljoen/mongoose-redis-caching/tree/master.svg?style=svg)](https://circleci.com/gh/pedreviljoen/mongoose-redis-caching/tree/master)
[![Greenkeeper badge](https://badges.greenkeeper.io/pedreviljoen/mongoose-redis-caching.svg)](https://greenkeeper.io/)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![Known Vulnerabilities](https://snyk.io//test/github/pedreviljoen/mongoose-redis-caching/badge.svg?targetFile=package.json)](https://snyk.io//test/github/pedreviljoen/mongoose-redis-caching?targetFile=package.json)

[![Package Quality](https://npm.packagequality.com/badge/mongoose-redis-caching.png)](https://packagequality.com/#?package=mongoose-redis-caching)

## About

A simple Mongoose Redis caching module.

## Installation

```sh
npm i mongoose-redis-caching
```

OR

```sh
yarn add mongoose-redis-caching
```

## Usage

Require in the module

```javascript
const mongoose = require("mongoose");
const mongooseRedisCaching = require("mongoose-redis-caching");
```

Configure your mongoose caching instance

```javascript
mongooseRedisCaching(mongoose);
```

Add your own Redis URL to your **.env** file. The default is set to your local redis instance.

Then use as below (with Caching & no compression):

```javascript
const blogs = await Blog.find({ _user: req.user.id }).cache();
```
With time expiration (in seconds, default is 60 sec):

```javascript
const blogs = await Blog.find({ _user: req.user.id }).cache(15);
```

Use as below (without Caching):

```javascript
const blogs = await Blog.find({ _user: req.user.id });
```

## License

MIT

## Coming soon

- [x] Expire items

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