Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fortis/koa-boost

Cache middleware for koa
https://github.com/fortis/koa-boost

cache koa koa-boost koa-cache koa-middleware koa2 koajs

Last synced: 26 days ago
JSON representation

Cache middleware for koa

Awesome Lists containing this project

README

        

# koa-boost

[![Greenkeeper badge](https://badges.greenkeeper.io/fortis/koa-boost.svg)](https://greenkeeper.io/)


travis-ci status
coverage status
npm version
Standard - JavaScript Style Guide

Cache middleware for [koa](https://github.com/koajs/koa).

## Installation

```sh
npm install koa-boost --save
```

## Usage

##### Store Cache in Application Memory
```js
const Koa = require('koa')
const boost = require('koa-boost')

const app = new Koa()
app.use(boost({
pattern: '/api/*',
ttl: 60 // 60 seconds
}));
```

##### Use Redis as Cache Provider
```js
const Koa = require('koa')
const boost = require('koa-boost')
const Redis = require('ioredis')

const app = new Koa()
const redis = new Redis()
app.use(boost({
provider: redis,
pattern: '/api/*',
ttl: 60 // 60 seconds
}));
```

### Options

* `pattern {string|array}` — pattern to match incoming request paths against. Supports glob matching and other
features provided by highly optimized wildcard and glob matching library [micromatch](https://github.com/micromatch/micromatch). Defaults to `null` — all requests will be cached.
* `ttl {integer}` — time in seconds that cached response should remain in the cache. Defaults to `60` seconds.