Skip to content

hodavidhara/koa-rest-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-rest-cache

Build Status

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).
  • method A String or Array of Strings to match incoming request methods against. Defaults to GET

About

Very simple cache middleware for restful apis in koa

Resources

License

Stars

Watchers

Forks

Packages

No packages published