cacheable-request 2.1.0 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  [![Build Status](https://travis-ci.org/lukechilds/cacheable-request.svg?branch=master)](https://travis-ci.org/lukechilds/cacheable-request)
6
6
  [![Coverage Status](https://coveralls.io/repos/github/lukechilds/cacheable-request/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/cacheable-request?branch=master)
7
+ [![npm](https://img.shields.io/npm/dm/cacheable-request.svg)](https://www.npmjs.com/package/cacheable-request)
7
8
  [![npm](https://img.shields.io/npm/v/cacheable-request.svg)](https://www.npmjs.com/package/cacheable-request)
8
9
 
9
10
  [RFC 7234](http://httpwg.org/specs/rfc7234.html) compliant HTTP caching for native Node.js HTTP/HTTPS requests. Caching works out of the box in memory or is easily pluggable with a wide range of storage adapters.
@@ -21,7 +22,7 @@
21
22
  - In memory cache by default
22
23
  - Official support for Redis, MongoDB, SQLite, PostgreSQL and MySQL storage adapters
23
24
  - Easily plug in your own or third-party storage adapters
24
- - If DB connection fails, cache is automatically bypassed
25
+ - If DB connection fails, cache is automatically bypassed ([disabled by default](#optsautomaticfailover))
25
26
  - Adds cache support to any existing HTTP code with minimal changes
26
27
  - Uses [http-cache-semantics](https://github.com/pornel/http-cache-semantics) internally for HTTP RFC 7234 compliance
27
28
 
@@ -134,6 +135,13 @@ If set to `false`, after a cached resource's TTL expires it is kept in the cache
134
135
 
135
136
  If set to `true` once a cached resource has expired it is deleted and will have to be re-requested.
136
137
 
138
+ ###### opts.automaticFailover
139
+
140
+ Type: `boolean`<br>
141
+ Default: `false`
142
+
143
+ When set to `true`, if the DB connection fails we will automatically fallback to a network request. DB errors will still be emitted to notify you of the problem even though the request callback may succeed.
144
+
137
145
  ##### cb
138
146
 
139
147
  Type: `function`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cacheable-request",
3
- "version": "2.1.0",
3
+ "version": "2.1.4",
4
4
  "description": "Wrap native HTTP requests with RFC compliant cache support",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -33,22 +33,21 @@
33
33
  },
34
34
  "homepage": "https://github.com/lukechilds/cacheable-request",
35
35
  "dependencies": {
36
- "clone-response": "1.0.1",
36
+ "clone-response": "1.0.2",
37
37
  "get-stream": "3.0.0",
38
- "http-cache-semantics": "3.8.0",
39
- "keyv": "3.0.0 ",
38
+ "http-cache-semantics": "3.8.1",
39
+ "keyv": "3.0.0",
40
40
  "lowercase-keys": "1.0.0",
41
- "normalize-url": "1.9.1",
42
- "responselike": "1.0.0"
41
+ "normalize-url": "2.0.1",
42
+ "responselike": "1.0.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@keyv/sqlite": "^1.2.6",
46
- "ava": "^0.23.0",
46
+ "ava": "^0.24.0",
47
47
  "coveralls": "^3.0.0",
48
48
  "create-test-server": "^2.0.0",
49
49
  "delay": "^2.0.0",
50
50
  "eslint-config-xo-lukechilds": "^1.0.0",
51
- "get-stream": "^3.0.0",
52
51
  "nyc": "^11.0.2",
53
52
  "pify": "^3.0.0",
54
53
  "sqlite3": "^3.1.9",
package/src/index.js CHANGED
@@ -34,7 +34,8 @@ class CacheableRequest {
34
34
  headers: {},
35
35
  method: 'GET',
36
36
  cache: true,
37
- strictTtl: false
37
+ strictTtl: false,
38
+ automaticFailover: false
38
39
  }, opts);
39
40
  opts.headers = lowercaseKeys(opts.headers);
40
41
 
@@ -124,7 +125,7 @@ class CacheableRequest {
124
125
  this.cache.on('error', err => ee.emit('error', new CacheableRequest.CacheError(err)));
125
126
 
126
127
  get(opts).catch(err => {
127
- if (!madeRequest) {
128
+ if (opts.automaticFailover && !madeRequest) {
128
129
  makeRequest(opts);
129
130
  }
130
131
  ee.emit('error', new CacheableRequest.CacheError(err));