koa-boost

Cache middleware for koa

koa-boost

Build Status Coverage Status

Cache middleware for koa. It stores the responses matching a given pattern.

Installation

npm install koa-boost --save

Usage

Store Cache in Application Memory
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
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. 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.