Socket
Socket
Sign inDemoInstall

lru-cache-for-clusters-as-promised

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lru-cache-for-clusters-as-promised - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

26

lru-cache-for-clusters-as-promised.js

@@ -25,12 +25,4 @@ /**

if (cluster.isWorker) {
process.on('message', (response) => {
// look up the callback based on the response ID, delete it, then call it
if (response.source !== source || !callbacks[response.id]) return;
const callback = callbacks[response.id];
delete callbacks[response.id];
callback(response);
});
// only run on the master thread
} else if (cluster.isMaster) {
// only run on the master thread
if (cluster.isMaster) {
// for each worker created...

@@ -80,2 +72,13 @@ cluster.on('fork', (worker) => {

// run on each worker thread
if (cluster.isWorker) {
process.on('message', (response) => {
// look up the callback based on the response ID, delete it, then call it
if (response.source !== source || !callbacks[response.id]) return;
const callback = callbacks[response.id];
delete callbacks[response.id];
callback(response);
});
}
/**

@@ -135,3 +138,3 @@ * LRUCacheForClustersAsPromised roughly approximates the functionality of LRUCache

failsafeTimeout = undefined;
return reject(new Error('Timed out in isFailed() timeout'));
return reject(new Error('Timed out in isFailed()'));
}, cache.timeout);

@@ -177,1 +180,2 @@ // set the callback for this id to resolve the promise

module.exports = LRUCacheForClustersAsPromised;
module.exports.init = () => true;
{
"name": "lru-cache-for-clusters-as-promised",
"version": "1.0.4",
"version": "1.0.5",
"description": "LRU Cache that is safe for clusters",
"main": "./lru-cache-for-clusters-as-promised.js",
"scripts": {
"test": "DEBUG=lru-cache-for-clusters-as-promised mocha ./test",
"test": "./node_modules/.bin/mocha ./test",
"coverage-report": "./node_modules/.bin/istanbul-coverage-report",

@@ -9,0 +9,0 @@ "coverage": "npm run coverage-report && open ./coverage/lcov-report/index.html",

@@ -66,2 +66,7 @@ # lru-cache-for-clusters-as-promised

```javascript
// require the module in your master thread that creates workers to initialize
const LRUCache = require('lru-cache-for-clusters-as-promised').init();
```javascript
const LRUCache = require('lru-cache-for-clusters-as-promised');

@@ -68,0 +73,0 @@ const cache = new LRUCache({

@@ -24,2 +24,16 @@ const request = require('supertest');

it('should timeout', (done) => {
// run the request
request(`http://${config.server.host}:${config.server.port}`)
.get('/timeout')
.expect(200)
.end((err, response) => {
if (err) {
return done(err);
}
response.text.should.eql('ok');
return done();
});
});
it('should set(key, value)', (done) => {

@@ -26,0 +40,0 @@ // run the request

const cluster = require('cluster');
const os = require('os');
const path = require('path');
const LRUCache = require('../../');
LRUCache.init();
// this is the path to the cluster worker that spawns the http server

@@ -6,0 +9,0 @@ const workerPath = path.join(__dirname, 'cluster-worker.js');

@@ -27,2 +27,14 @@ const http = require('http');

app.get('/timeout', (req, res) => {
const cacheBad = new LRUCache({
max: 3,
stale: false,
timeout: 1,
namespace: 'bad-cache',
});
return cacheBad.get('test')
.then(() => res.send('fail'))
.catch(() => res.send('ok'));
});
app.get('/set', (req, res) => {

@@ -29,0 +41,0 @@ cache.set(config.args.one, config.args.one)

@@ -29,4 +29,3 @@ const should = require('should');

return done();
})
.catch(err => done(err));
});
});

@@ -33,0 +32,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc