lru-cache-for-clusters-as-promised
Advanced tools
Comparing version 1.0.6 to 1.1.0
@@ -104,2 +104,5 @@ /** | ||
// how should timeouts be handled - default is resolve(undefined), otherwise reject(Error) | ||
cache.failsafe = options.failsafe === 'reject' ? 'reject' : 'resolve'; | ||
// return a promise that resolves to the result of the method on | ||
@@ -137,3 +140,6 @@ // the local lru-cache this is the master thread, or from the | ||
failsafeTimeout = undefined; | ||
return reject(new Error('Timed out in isFailed()')); | ||
if (cache.failsafe === 'reject') { | ||
return reject(new Error('Timed out in isFailed()')); | ||
} | ||
return resolve(undefined); | ||
}, cache.timeout); | ||
@@ -140,0 +146,0 @@ // set the callback for this id to resolve the promise |
{ | ||
"name": "lru-cache-for-clusters-as-promised", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"description": "LRU Cache that is safe for clusters", | ||
@@ -5,0 +5,0 @@ "main": "./lru-cache-for-clusters-as-promised.js", |
@@ -28,2 +28,4 @@ # lru-cache-for-clusters-as-promised | ||
* The amount of time in milliseconds that a worker will wait for a response from the master before rejecting the Promise. | ||
* `failsafe: string`, default `resolve`. | ||
* When a request times out the Promise will return `resolve(undefined)` by default, or with a value of `reject` the return will be `reject(Error)`. | ||
* `max: number` | ||
@@ -30,0 +32,0 @@ * the maximum items that can be stored in the cache |
@@ -38,2 +38,16 @@ const request = require('supertest'); | ||
it('should timeout with reject', (done) => { | ||
// run the request | ||
request(`http://${config.server.host}:${config.server.port}`) | ||
.get('/reject') | ||
.expect(200) | ||
.end((err, response) => { | ||
if (err) { | ||
return done(err); | ||
} | ||
response.text.should.eql('ok'); | ||
return done(); | ||
}); | ||
}); | ||
it('should set(key, value)', (done) => { | ||
@@ -40,0 +54,0 @@ // run the request |
@@ -35,2 +35,14 @@ const http = require('http'); | ||
return cacheBad.get('test') | ||
.then(result => res.send(result === undefined ? 'ok' : 'fail')); | ||
}); | ||
app.get('/reject', (req, res) => { | ||
const cacheBad = new LRUCache({ | ||
max: 3, | ||
stale: false, | ||
timeout: 1, | ||
failsafe: 'reject', | ||
namespace: 'bad-cache2', | ||
}); | ||
return cacheBad.get('test') | ||
.then(() => res.send('fail')) | ||
@@ -42,4 +54,3 @@ .catch(() => res.send('ok')); | ||
cache.set(config.args.one, config.args.one) | ||
.then(result => res.send(result)) | ||
.catch(err => res.send(err)); | ||
.then(result => res.send(result)); | ||
}); | ||
@@ -50,4 +61,3 @@ | ||
.then(() => cache.get(config.args.one)) | ||
.then(result => res.send(result)) | ||
.catch(err => res.send(err)); | ||
.then(result => res.send(result)); | ||
}); | ||
@@ -68,4 +78,3 @@ | ||
.then(() => cache.get(config.args.one)) | ||
.then(result => res.send(result)) | ||
.catch(err => res.send(err)); | ||
.then(result => res.send(result)); | ||
}); | ||
@@ -80,4 +89,3 @@ | ||
.then(() => cache.get(config.args.one)) | ||
.then(result => res.send(result)) | ||
.catch(err => res.send(err)); | ||
.then(result => res.send(result)); | ||
}); | ||
@@ -99,4 +107,3 @@ | ||
return res.send(vals); | ||
}) | ||
.catch(err => res.send(err)); | ||
}); | ||
}); | ||
@@ -107,4 +114,3 @@ | ||
.then(() => cache.has(config.args.one)) | ||
.then(result => res.send(result)) | ||
.catch(err => res.send(err)); | ||
.then(result => res.send(result)); | ||
}); | ||
@@ -123,4 +129,3 @@ | ||
return res.send(vals); | ||
}) | ||
.catch(err => res.send(err)); | ||
}); | ||
}); | ||
@@ -131,4 +136,3 @@ | ||
.then(() => cache.itemCount()) | ||
.then(result => res.send({ result })) | ||
.catch(err => res.send(err)); | ||
.then(result => res.send({ result })); | ||
}); | ||
@@ -153,8 +157,5 @@ | ||
cache.set(config.args.one, config.args.one) | ||
.then(() => cache.prune() | ||
.catch(err => res.send(err))) | ||
.then(() => cache.itemCount() | ||
.catch(err => res.send(err))) | ||
.then(result => res.send({ result })) | ||
.catch(err => res.send(err)); | ||
.then(() => cache.prune()) | ||
.then(() => cache.itemCount()) | ||
.then(result => res.send({ result })); | ||
}); | ||
@@ -165,4 +166,3 @@ | ||
.then(() => cache.dump()) | ||
.then(result => res.send({ result })) | ||
.catch(err => res.send(err)); | ||
.then(result => res.send({ result })); | ||
}); | ||
@@ -169,0 +169,0 @@ |
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
31965
719
146