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.3 to 1.0.4

8

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

@@ -98,2 +98,5 @@ /**

// this is how long the worker will wait for a response from the master in milliseconds
cache.timeout = options.timeout || 100;
// return a promise that resolves to the result of the method on

@@ -132,3 +135,3 @@ // the local lru-cache this is the master thread, or from the

return reject(new Error('Timed out in isFailed() timeout'));
}, 100);
}, cache.timeout);
// set the callback for this id to resolve the promise

@@ -138,4 +141,5 @@ callbacks[request.id] = (result) => {

clearTimeout(failsafeTimeout);
return resolve(result.value);
}
return resolve(result.value);
return false;
};

@@ -142,0 +146,0 @@ // send the request to the master process

{
"name": "lru-cache-for-clusters-as-promised",
"version": "1.0.3",
"version": "1.0.4",
"description": "LRU Cache that is safe for clusters",

@@ -33,8 +33,8 @@ "main": "./lru-cache-for-clusters-as-promised.js",

"lru-cache": "^4.0.1",
"uuid": "^2.0.2"
"uuid": "^2.0.3"
},
"devDependencies": {
"developer-tools": "0.0.2",
"eslint-config-airbnb": "^11.1.0",
"eslint-plugin-import": "^1.15.0",
"developer-tools": "0.0.3",
"eslint-config-airbnb": "^12.0.0",
"eslint-plugin-import": "^1.16.0",
"eslint-plugin-jsx-a11y": "^2.2.2",

@@ -41,0 +41,0 @@ "eslint-plugin-mocha": "^4.5.1",

@@ -17,4 +17,2 @@ # lru-cache-for-clusters-as-promised

To differentiate caches on the master as instances on the `workers`, specify a `namespace` value in the options argument of the `new LRUCache(options)` constructor.
# install

@@ -25,2 +23,44 @@ ```shell

# options
* `namespace: string`, default `"default"`;
* the namespace for this cache on the master thread as it is not aware of the worker instances
* `timeout: integer`, default `100`.
* The amount of time in milliseconds that a worker will wait for a response from the master before rejecting the Promise.
* `max: number`
* the maximum items that can be stored in the cache
* `maxAge: milliseconds`
* the maximum age for an item to be considered valid
* `stale: true|false`
* when true expired items are return before they are removed rather than undefined
> ! note that `length` and `dispose` are missing as it is not possible to pass `functions` via IPC messages.
# api
* `set(key, value)`
* sets a value for a key
* `get(key)`
* returns a value for a key
* `peek(key)`
* return the value for a key without updating its last access time
* `del(key)`
* remove a value from the cache
* `has(key)`
* returns true if the key exists in the cache
* `reset()`
* removes all values from the cache
* `keys()`
* returns an array of all the cache keys
* `values()`
* returns an array of all the cache values
* `dump()`
* returns a serialized array of the cache contents
* `prune()`
* manually removes items from the cache rather than on get
* `length()`
* return the number of items in the cache
* `itemCount()`
* return the number of items in the cache. same as `length()`.
# example usage

@@ -70,45 +110,5 @@ ```javascript

# options
* `namespace: string`
* the namespace for this cache on the master thread as it is not aware of the worker instances
* `max: number`
* the maximum items that can be stored in the cache
* `maxAge: milliseconds`
* the maximum age for an item to be considered valid
* `stale: true|false`
* when true expired items are return before they are removed rather than undefined
> ! note that `length` and `dispose` are missing as it is not possible to pass `functions` via IPC messages.
# api
* `set(key, value)`
* sets a value for a key
* `get(key)`
* returns a value for a key
* `peek(key)`
* return the value for a key without updating its last access time
* `del(key)`
* remove a value from the cache
* `has(key)`
* returns true if the key exists in the cache
* `reset()`
* removes all values from the cache
* `keys()`
* returns an array of all the cache keys
* `values()`
* returns an array of all the cache values
* `dump()`
* returns a serialized array of the cache contents
* `prune()`
* manually removes items from the cache rather than on get
* `length()`
* return the number of items in the cache
* `itemCount()`
* return the number of items in the cache. same as `length()`.
# process flow
**Clustered cache on master thread for clustered environments***
**Clustered cache on master thread for clustered environments**
```

@@ -133,3 +133,3 @@ +-----+

**Promisified for non-clustered environments***
**Promisified for non-clustered environments**
```

@@ -136,0 +136,0 @@ +---------------+ +---------------+ +---------+ +-----------+

const cluster = require('cluster');
const os = require('os');
const path = require('path');

@@ -43,8 +44,11 @@

// fork a new worker
cluster.fork();
cluster.fork();
let isDone = false;
// create one process per CPU core
const workers = os.cpus().length;
for (let i = 0; i < workers; i += 1) {
cluster.fork();
}
let listeningCount = 0;
// provide a function for mocha so we can call back when the worker is ready

@@ -56,5 +60,5 @@ module.exports = (done) => {

worker.on('listening', () => {
listeningCount += 1;
// tell mocha we are good to go
if (!isDone) {
isDone = true;
if (listeningCount === workers) {
done();

@@ -61,0 +65,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