Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/fortis/koa-boost
- Owner: fortis
- Created: 2017-05-28T17:00:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-23T03:13:19.000Z (almost 7 years ago)
- Last Synced: 2024-11-14T16:20:22.816Z (2 months ago)
- Topics: cache, koa, koa-boost, koa-cache, koa-middleware, koa2, koajs
- Language: JavaScript
- Homepage:
- Size: 84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# koa-boost
[![Greenkeeper badge](https://badges.greenkeeper.io/fortis/koa-boost.svg)](https://greenkeeper.io/)
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.