0.5.4 • Published 9 years ago

koa-ssdb-cache v0.5.4

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

NPM version Build status Test coverage License Dependency status

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:
  • expire
    • type: Number
    • ssdb expire time (second), default is 30 * 60 (30 min)
  • passParam
    • type: String
    • if the passParam is existed in query string, not get from cache
  • maxLength
    • type: Number
    • max length of the body to cache
  • routes
    • type: Array
    • the routes to cache, default is ['(.*)']
    • It could be ['/api/(.*)', '/view/:id'], see path-to-regexp
  • exclude
    • type: Array
    • the routes to exclude, default is []
    • It could be ['/api/(.*)', '/view/:id'], see path-to-regexp
  • onerror
    • type: Function
    • callback function for error, default is function() {}
  • ssdb
    • type: Object
    • ssdb options
  • ssdb.port
    • type: Number
  • ssdb.host
    • type: String
  • ssdb.options

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 header X-Koa-SSDB-Cache: true when the response is from cache

License

MIT

0.5.4

9 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago