koa-rest-cache
v1.1.0
Published
Very simple cache middleware for restful apis in koa
Downloads
7
Readme
koa-rest-cache
Very simple cache middleware for restful apis in koa. This aims to be a very thin wrapper over your restful APIs. It simply stores the response body of requests matching a given pattern in memory. There is no way to read, write, or clear the cache, it should just work.
Installation
npm install koa-rest-cache
Usage
var app = require('koa')();
var cache = require('koa-rest-cache');
app.use(cache({
pattern: "/api/**/*",
maxAge: 600000 // ms
}));
API
cache(options)
A function that takes a single options
argument, and returns a function generator that is intended
to be passed to koa's app.use
function.
Options
pattern
A String or Array of Strings to match incoming request paths against. Supports glob matching and other features provided by minimatch. If no pattern is provided all requests will be cached.maxAge
A length of time in milliseconds that something should remain in the cache. Defaults to 600000ms (10 minutes).