From 011ea0e50c1171553c85d9ba0f151ba02860ad97 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Mon, 8 May 2017 18:28:46 +0700 Subject: [PATCH] Include method in cache key --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9334c65..8a9912b 100644 --- a/index.js +++ b/index.js @@ -68,7 +68,7 @@ function requestAsEventEmitter(opts) { stream .then(data => { - const key = normalizeUrl(response.url); + const key = cacheKey(opts); const value = JSON.stringify({ policy: policy.toObject(), response: { @@ -105,7 +105,7 @@ function requestAsEventEmitter(opts) { }; if (opts.cache) { - const key = normalizeUrl(requestUrl); + const key = cacheKey(opts); opts.cache.get(key, (err, value) => { if (err) { return get(opts); @@ -340,6 +340,11 @@ function normalizeArguments(url, opts) { return opts; } +function cacheKey(opts) { + const url = normalizeUrl(urlLib.format(opts)); + return `${opts.method}:${url}`; +} + function responseFromCache(url, cachedResponse) { return new Response(200, cachedResponse.headers, Buffer.from(cachedResponse.body), url); }