Non Productive Monday

    koa-ssdb-cache

    0.5.4 • Public • Published

    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

    Install

    npm i koa-ssdb-cache

    DownloadsWeekly Downloads

    0

    Version

    0.5.4

    License

    MIT

    Last publish

    Collaborators

    • iwater