Socket
Socket
Sign inDemoInstall

cacheable-request

Package Overview
Dependencies
9
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.4 to 3.0.0

109

package.json
{
"name": "cacheable-request",
"version": "2.1.4",
"description": "Wrap native HTTP requests with RFC compliant cache support",
"main": "src/index.js",
"scripts": {
"test": "xo && nyc ava",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"xo": {
"extends": "xo-lukechilds"
},
"repository": {
"type": "git",
"url": "git+https://github.com/lukechilds/cacheable-request.git"
},
"keywords": [
"HTTP",
"HTTPS",
"cache",
"caching",
"layer",
"cacheable",
"RFC 7234",
"RFC",
"7234",
"compliant"
],
"author": "Luke Childs <lukechilds123@gmail.com> (http://lukechilds.co.uk)",
"license": "MIT",
"bugs": {
"url": "https://github.com/lukechilds/cacheable-request/issues"
},
"homepage": "https://github.com/lukechilds/cacheable-request",
"dependencies": {
"clone-response": "1.0.2",
"get-stream": "3.0.0",
"http-cache-semantics": "3.8.1",
"keyv": "3.0.0",
"lowercase-keys": "1.0.0",
"normalize-url": "2.0.1",
"responselike": "1.0.2"
},
"devDependencies": {
"@keyv/sqlite": "^1.2.6",
"ava": "^0.24.0",
"coveralls": "^3.0.0",
"create-test-server": "^2.0.0",
"delay": "^2.0.0",
"eslint-config-xo-lukechilds": "^1.0.0",
"nyc": "^11.0.2",
"pify": "^3.0.0",
"sqlite3": "^3.1.9",
"this": "^1.0.2",
"xo": "^0.19.0"
}
"name": "cacheable-request",
"version": "3.0.0",
"description": "Wrap native HTTP requests with RFC compliant cache support",
"license": "MIT",
"repository": "lukechilds/cacheable-request",
"author": "Luke Childs <lukechilds123@gmail.com> (http://lukechilds.co.uk)",
"main": "src/index.js",
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && nyc ava",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"files": [
"src"
],
"keywords": [
"HTTP",
"HTTPS",
"cache",
"caching",
"layer",
"cacheable",
"RFC 7234",
"RFC",
"7234",
"compliant"
],
"dependencies": {
"clone-response": "^1.0.2",
"get-stream": "^3.0.0",
"http-cache-semantics": "^4.0.0",
"keyv": "^3.0.0",
"lowercase-keys": "^1.0.1",
"normalize-url": "^3.1.0",
"responselike": "^1.0.2"
},
"devDependencies": {
"@keyv/sqlite": "^1.2.6",
"ava": "*",
"coveralls": "^3.0.0",
"create-test-server": "2.1.1",
"delay": "^3.0.0",
"eslint-config-xo-lukechilds": "^1.0.0",
"nyc": "^12.0.2",
"pify": "^3.0.0",
"sqlite3": "^4.0.1",
"this": "^1.0.2",
"xo": "*"
},
"xo": {
"extends": "xo-lukechilds"
}
}

@@ -32,3 +32,3 @@ # cacheable-request

```shell
npm install --save cacheable-request
npm install cacheable-request
```

@@ -64,3 +64,3 @@

```
npm install --save @keyv/redis
npm install @keyv/redis
```

@@ -67,0 +67,0 @@

@@ -69,4 +69,7 @@ 'use strict';

clonedResponse = cloneResponse(response);
getStream.buffer(response)
.then(body => {
(async () => {
try {
const body = await getStream.buffer(response);
const value = {

@@ -79,8 +82,15 @@ cachePolicy: response.cachePolicy.toObject(),

const ttl = opts.strictTtl ? response.cachePolicy.timeToLive() : undefined;
return this.cache.set(key, value, ttl);
})
.catch(err => ee.emit('error', new CacheableRequest.CacheError(err)));
await this.cache.set(key, value, ttl);
} catch (err) {
ee.emit('error', new CacheableRequest.CacheError(err));
}
})();
} else if (opts.cache && revalidate) {
this.cache.delete(key)
.catch(err => ee.emit('error', new CacheableRequest.CacheError(err)));
(async () => {
try {
await this.cache.delete(key);
} catch (err) {
ee.emit('error', new CacheableRequest.CacheError(err));
}
})();
}

@@ -102,5 +112,7 @@

const get = opts => Promise.resolve()
.then(() => opts.cache ? this.cache.get(key) : undefined)
.then(cacheEntry => {
(async () => {
const get = async opts => {
await Promise.resolve();
const cacheEntry = opts.cache ? await this.cache.get(key) : undefined;
if (typeof cacheEntry === 'undefined') {

@@ -126,12 +138,15 @@ return makeRequest(opts);

}
});
};
this.cache.on('error', err => ee.emit('error', new CacheableRequest.CacheError(err)));
this.cache.on('error', err => ee.emit('error', new CacheableRequest.CacheError(err)));
get(opts).catch(err => {
if (opts.automaticFailover && !madeRequest) {
makeRequest(opts);
try {
await get(opts);
} catch (err) {
if (opts.automaticFailover && !madeRequest) {
makeRequest(opts);
}
ee.emit('error', new CacheableRequest.CacheError(err));
}
ee.emit('error', new CacheableRequest.CacheError(err));
});
})();

@@ -138,0 +153,0 @@ return ee;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc