Skip to content

Commit a692392

Browse files
committed
feat: add all options to getKey params
1 parent 9d6f623 commit a692392

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ The value will be associated with [`stale-while-revalidate`](https://www.mnot.ne
185185
##### getKey
186186

187187
Type: `function`<br/>
188-
Default: `(req, res) => normalizeUrl(req.url)`
188+
Default: `({ req }) => normalizeUrl(req.url)`
189189

190190
It determinates how the cache key should be computed, receiving `req, res` as input.
191191

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function isEmpty (value) {
1919
)
2020
}
2121

22-
const _getKey = req => {
22+
const _getKey = ({ req }) => {
2323
const url = new URL(req.url, 'http://localhost').toString()
2424
const { origin } = new URL(url)
2525
const baseKey = normalizeUrl(url, {
@@ -79,14 +79,15 @@ module.exports = ({
7979
...compressOpts
8080
})
8181

82-
return async ({ req, res, ...opts }) => {
82+
return async opts => {
83+
const { req, res } = opts;
8384
const hasForce = Boolean(
8485
req.query ? req.query.force : parse(req.url.split('?')[1]).force
8586
)
86-
const key = getKey(req, res)
87+
const key = getKey(opts)
8788
const cachedResult = await decompress(await cache.get(key))
8889
const isHit = !hasForce && cachedResult !== undefined
89-
const result = isHit ? cachedResult : await get({ req, res, ...opts })
90+
const result = isHit ? cachedResult : await get(opts)
9091

9192
if (!result) return
9293

0 commit comments

Comments
 (0)