cacheable-response
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="1.4.2"></a> | ||
## [1.4.2](https://github.com/Kikobeats/cacheable-response/compare/v1.4.1...v1.4.2) (2019-04-06) | ||
<a name="1.4.1"></a> | ||
@@ -7,0 +12,0 @@ ## [1.4.1](https://github.com/Kikobeats/cacheable-response/compare/v1.4.0...v1.4.1) (2019-04-06) |
25
index.js
@@ -57,3 +57,4 @@ 'use strict' | ||
const setHeaders = createSetHeaders({ | ||
revalidate: typeof revalidate === 'function' ? revalidate : () => revalidate | ||
revalidate: | ||
typeof revalidate === 'function' ? revalidate : () => revalidate | ||
}) | ||
@@ -64,3 +65,5 @@ | ||
return async ({ req, res, ...opts }) => { | ||
const hasForce = Boolean(req.query ? req.query.force : parse(req.url.split('?')[1]).force) | ||
const hasForce = Boolean( | ||
req.query ? req.query.force : parse(req.url.split('?')[1]).force | ||
) | ||
@@ -70,13 +73,13 @@ // Because req.url is relative, we need to convert it into an absolute url | ||
const key = getKey(urlResolve('u:', req.url)) | ||
const cachedResult = await decompress(await cache.get(key)) | ||
const isHit = !hasForce && cachedResult !== undefined | ||
const cachedData = await cache.get(key) | ||
const hasData = cachedData !== undefined | ||
const isHit = !hasForce && hasData | ||
const { | ||
etag: cachedEtag, | ||
ttl = defaultTtl, | ||
createdAt = Date.now(), | ||
data, | ||
...props | ||
} = cachedResult || (await get({ req, res, ...opts })) | ||
const cachedResult = await decompress(cachedData) | ||
const { etag: cachedEtag, ttl = defaultTtl, createdAt = Date.now(), data, ...props } = isHit | ||
? cachedResult | ||
: await get({ req, res, ...opts }) | ||
const etag = cachedEtag || getEtag(data) | ||
@@ -83,0 +86,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://nicedoc.io/Kikobeats/cacheable-response", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"main": "index.js", | ||
@@ -8,0 +8,0 @@ "author": { |
20539
85