Socket
Socket
Sign inDemoInstall

lru-cache-for-clusters-as-promised

Package Overview
Dependencies
9
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.4.1

30

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

@@ -70,6 +70,18 @@ /**

case '()': {
let created = false;
const options = request.arguments[0];
// create a new lru-cache, give it a namespace, and save it locally
if (caches[request.namespace]) {
lru = caches[request.namespace];
if (options.max && options.max !== lru.max) {
lru.max = options.max;
}
if (options.maxAge && options.maxAge !== lru.maxAge) {
lru.maxAge = options.maxAge;
}
if (options.stale && options.stale !== lru.stale) {
lru.stale = options.stale;
}
} else {
created = true;
lru = caches[request.namespace] = new LRUCache(...request.arguments);

@@ -83,6 +95,7 @@ // start a job to clean the cache

value: {
namespace: request.namespace,
isnew: created,
max: lru.max,
maxAge: lru.maxAge,
stale: lru.stale,
namespace: request.namespace,
},

@@ -160,3 +173,6 @@ });

*/
function LRUCacheForClustersAsPromised(options) {
function LRUCacheForClustersAsPromised(opts) {
// default to some empty options
const options = opts || {};
// keep a reference as 'this' is lost inside the Promise contexts

@@ -179,4 +195,7 @@ const cache = this;

lru = caches[cache.namespace];
debug('Loaded cache out of shared namespace');
} else {
debug('Created new LRU cache');
lru = new LRUCache(options);
caches[cache.namespace] = lru;
if (options.prune) {

@@ -246,3 +265,3 @@ lru.job = startPruneCronJob(lru, options.prune);

return resolve(undefined);
}, cache.timeout);
}, func === '()' ? 5000 : cache.timeout);
// set the callback for this id to resolve the promise

@@ -265,3 +284,6 @@ callbacks[request.id] = (result) => {

.then(lruOptions => debug('created lru cache on master', lruOptions))
.catch(err => debug('failed to create lru cache on master', err, options));
.catch((err) => {
/* istanbul ignore next */
debug('failed to create lru cache on master', err, options);
});
}

@@ -268,0 +290,0 @@

2

package.json
{
"name": "lru-cache-for-clusters-as-promised",
"version": "1.4.0",
"version": "1.4.1",
"description": "LRU Cache that is safe for clusters",

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

@@ -8,4 +8,9 @@ const config = require('./config');

// this will be the SAME cache no matter which module calls it.
const initCache = new LRUCache();
initCache.keys();
// this will be the SAME cache no matter which module calls it.
const defaultCache = new LRUCache({
max: 1,
maxAge: 100000,
stale: true,
});

@@ -15,5 +20,4 @@ defaultCache.keys();

const cache = new LRUCache({
namespace: 'test-cache',
max: 3,
stale: false,
namespace: 'test-cache',
});

@@ -20,0 +24,0 @@

@@ -6,2 +6,3 @@ const LRUCache = require('../');

const cache = new LRUCache({
namespace: 'lru-cache-as-promised',
max: 3,

@@ -8,0 +9,0 @@ stale: false,

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