3.0.3 • Published 4 years ago
koa-redis-cache v3.0.3
koa-redis-cache
How to use ?
const cache = require('koa-redis-cache')
const Koa = require('koa')
const app = new Koa()
const options = {
expire: 60,
routes: ['/index']
}
app.use(cache(options))
options
- prefix
- type:
String
orFunction
- redis key prefix, default is
koa-redis-cache:
- If a function is supplied, its signature should be
function(ctx) {}
and it should return a string to use as the redis key prefix
- type:
- expire
- type:
Number
- redis 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:
- redis
- type:
Object
- redis options
- type:
- redis.port
- type:
Number
- type:
- redis.host
- type:
String
- type:
- redis.options
- type:
Object
- see node_redis
- type:
set different expire for each route
const cache = require('koa-redis-cache')
const Koa = require('koa')
const app = new Koa()
const options = {
routes: [{
path: '/index',
expire: 60
}, {
path: '/user',
expire: 5
}]
}
app.use(cache(options))
notes
koa-redis-cache
will set a custom http headerX-Koa-Redis-Cache: true
when the response is from cache
License
MIT
3.0.3
4 years ago
3.0.2
6 years ago
3.0.1
6 years ago
3.0.0
7 years ago
2.0.0
7 years ago
1.1.1
8 years ago
1.1.0
8 years ago
1.0.0
9 years ago
0.5.0
10 years ago
0.4.0
10 years ago
0.3.0
10 years ago
0.2.0
10 years ago
0.1.0
10 years ago
0.0.9
10 years ago
0.0.8
10 years ago
0.0.7
10 years ago
0.0.6
10 years ago
0.0.5
10 years ago
0.0.4
10 years ago
0.0.3
10 years ago
0.0.2
10 years ago
0.0.1
10 years ago
0.0.0
10 years ago