koa-ssdb-cache
v0.5.4
Published
a middleware for koa to cache response with ssdb.
Downloads
2
Maintainers
Readme
koa-ssdb-cache
how to use
var koa = require('koa'),
app = koa(),
cache = require('koa-ssdb-cache');
var options = {
expire: 60,
routes: ['/index']
};
app.use(cache(options));
options
- prefix
- type:
String
- ssdb key prefix, default is
koa-ssdb-cache:
- type:
- expire
- type:
Number
- ssdb expire time (second), default is
30 * 60
(30 min)
- type:
- passParam
- type:
String
- if the passParam is existed in query string, not get from cache
- type:
- maxLength
- type:
Number
- max length of the body to cache
- type:
- routes
- type:
Array
- the routes to cache, default is
['(.*)']
- It could be
['/api/(.*)', '/view/:id']
, see path-to-regexp
- type:
- exclude
- type:
Array
- the routes to exclude, default is
[]
- It could be
['/api/(.*)', '/view/:id']
, see path-to-regexp
- type:
- onerror
- type:
Function
- callback function for error, default is
function() {}
- type:
- ssdb
- type:
Object
- ssdb options
- type:
- ssdb.port
- type:
Number
- type:
- ssdb.host
- type:
String
- type:
- ssdb.options
- type:
Object
- see node_ssdb
- type:
set different expire for each route
var koa = require('koa'),
app = koa(),
cache = require('koa-ssdb-cache');
var options = {
routes: [{
path: '/index',
expire: 60
}, {
path: '/user',
expire: 5
}]
};
app.use(cache(options));
notes
koa-ssdb-cache
will set a custom http headerX-Koa-SSDB-Cache: true
when the response is from cache
License
MIT