@zhike/cache-koa-middleware
Advanced tools
Comparing version 1.2.0 to 1.4.0
23
index.js
@@ -18,2 +18,7 @@ 'use strict'; | ||
const clientMaxAgeHeader = options.clientMaxAgeHeader; | ||
if (clientMaxAgeHeader && typeof clientMaxAgeHeader !== 'string') { | ||
throw new Error('options.clientMaxAgeHeader must be a string'); | ||
} | ||
let keyFn = ctx => { | ||
@@ -30,4 +35,3 @@ let sortedKeys = Object.keys(ctx.query).sort(); | ||
keyFn = options.keyGenerator; | ||
} | ||
else { | ||
} else { | ||
throw new Error('options.keyGenerator must be a function which returns a string as redis key'); | ||
@@ -41,4 +45,3 @@ } | ||
skipCacheFn = options.skipCacheFn; | ||
} | ||
else { | ||
} else { | ||
throw new Error('options.skipCacheFn must be a function which returns a Promise'); | ||
@@ -52,4 +55,3 @@ } | ||
throw new Error('options.commandTimeout must be an integer larger than zero'); | ||
} | ||
else { | ||
} else { | ||
commandTimeout = options.commandTimeout; | ||
@@ -72,7 +74,12 @@ } | ||
ctx.set(response.headers); | ||
if (clientMaxAgeHeader) { | ||
let maxAge = await redis.ttl(redisKey).timeout(commandTimeout); | ||
if (maxAge > 0) { | ||
ctx.set(clientMaxAgeHeader, maxAge); | ||
} | ||
} | ||
ctx.body = response.body; | ||
return; | ||
} | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
// failed to get cache, move on | ||
@@ -79,0 +86,0 @@ } |
{ | ||
"name": "@zhike/cache-koa-middleware", | ||
"version": "1.2.0", | ||
"version": "1.4.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -92,2 +92,3 @@ const cache = require('../index') | ||
it('2nd expire', function (done) { | ||
this.timeout(5000); | ||
setTimeout(() => { | ||
@@ -94,0 +95,0 @@ request() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11642
7
370