Socket
Book a DemoInstallSign in
Socket

koa2-url-cache

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa2-url-cache

Koa2 middleware for cache response data

Source
npmnpm
Version
1.0.4
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

koa2-url-cache

Koa 2 middleware for cache response data.

  • regular match url. path-to-regexp
  • cache data in redis.

Install

npm install koa2-url-cache --save

Get start

const config = {
  redis: {
    host: '121.196.203.34',
    port: 6379,
    password: '',
    db: 0,
  },
  urls: {
    '/api/user/:name': {
      ttl: 30, // seconds
    }
  }
}
app.use(cache(config));

Config

redis

node_redis

prefix [optional]

  • Default 'page'
  • prefix is redis prefix key to storage cache data.

disable [optional]

  • Default false
  • Diasble cache for all routes

loggerLevel [optional]

addHeaders {Object} [optional]

Add all key-value to response headers.

  addHeaders: {
    "Access-Control-Allow-Origin": "http://localhost:8080",
    "Access-Control-Allow-Methods": "POST, GET, OPTIONS",
    "Access-Control-Allow-Headers": "*"
  }

urls {Object}

  • key is match by path-to-regexp
    • ttl {integer} expire in ttl. seconds
    • addHeaders {Object}. It will cover the top level addHeaders
    '/api/user': {
      ttl: '30', // seconds
      addHeaders: { // custom headers
        'x-power':'lx'
      }
    },

example:

FAQs

Package last updated on 20 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts