Comparing version 1.0.2 to 1.1.0
@@ -18,10 +18,11 @@ 'use strict'; | ||
function gotCached(options) { | ||
if (!options.cache) throw Error('cache is a required option'); | ||
var cache = options.cache; | ||
function gotCached(config) { | ||
if (!config.cache) throw Error('cache is a required option'); | ||
var cache = config.cache; | ||
function setCache(key, response) { | ||
function setCache(key, response, options) { | ||
var promise = response.then(function (response) { | ||
cache.set(key, response.body); | ||
var value = options.json ? JSON.stringify(response.body) : response.body; | ||
cache.set(key, value); | ||
@@ -34,5 +35,6 @@ return Promise.resolve(response); | ||
function getCache(key) { | ||
function getCache(key, options) { | ||
var promise = cache.get(key).then(function (value) { | ||
if (!value) return null; | ||
if (options.json) value = JSON.parse(value); | ||
@@ -56,3 +58,3 @@ return Promise.resolve({ | ||
var cachedResponse = getCache(url).then(function (cached) { | ||
var cachedResponse = getCache(url, options).then(function (cached) { | ||
// return the cached result if it exist | ||
@@ -62,3 +64,3 @@ if (cached) return cached; | ||
// return got response but first set cache with it | ||
return setCache(url, (0, _got2.default)(url, options)); | ||
return setCache(url, (0, _got2.default)(url, options), options); | ||
}); | ||
@@ -69,7 +71,3 @@ | ||
for (var prop in _got2.default) { | ||
cachedGot[prop] = _got2.default[prop]; | ||
} | ||
return cachedGot; | ||
return Object.assign(cachedGot, _got2.default); | ||
} |
{ | ||
"name": "got-cached", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Got response cache for get requests", | ||
@@ -18,3 +18,4 @@ "author": "janneh", | ||
"build": "babel -d ./build index.js", | ||
"prepublish": "npm run build" | ||
"prepublish": "npm run build", | ||
"postpublish": "rm -r ./build" | ||
}, | ||
@@ -21,0 +22,0 @@ "dependencies": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3788
4
0
48