lru-cache-for-clusters-as-promised
Advanced tools
Comparing version 1.5.9 to 1.5.10
@@ -0,1 +1,6 @@ | ||
1.5.10 / 2017-05-07 | ||
================== | ||
* Deduplicate common methods - fixes CodeClimate rating to 4.0 | ||
1.5.9 / 2017-05-06 | ||
@@ -2,0 +7,0 @@ ================== |
@@ -52,2 +52,26 @@ /** | ||
const funcs = { | ||
mapObjects: (pairs, objs, jsonFunction) => | ||
Promise.all( | ||
Object.keys(pairs).map((key) => Promise.resolve((objs[key] = JSON[jsonFunction](pairs[key])))) | ||
), | ||
mDel: (lru, params) => { | ||
if (params[0] && params[0] instanceof Array) { | ||
params[0].map((key) => lru.del(key)); | ||
} | ||
}, | ||
mGet: (lru, params) => { | ||
const mGetValues = {}; | ||
if (params[0] && params[0] instanceof Array) { | ||
params[0].map((key) => (mGetValues[key] = lru.get(key))); | ||
} | ||
return mGetValues; | ||
}, | ||
mSet: (lru, params) => { | ||
if (params[0] && params[0] instanceof Object) { | ||
Object.keys(params[0]).map((key) => lru.set(key, params[0][key], params[1])); | ||
} | ||
}, | ||
}; | ||
// only run on the master thread | ||
@@ -141,6 +165,3 @@ if (cluster.isMaster) { | ||
case 'mGet': { | ||
const mGetValues = {}; | ||
if (params[0] && params[0] instanceof Array) { | ||
params[0].map((key) => (mGetValues[key] = lru.get(key))); | ||
} | ||
const mGetValues = funcs.mGet(lru, params); | ||
sendResponse({ value: mGetValues }); | ||
@@ -150,5 +171,3 @@ break; | ||
case 'mSet': { | ||
if (params[0] && params[0] instanceof Object) { | ||
Object.keys(params[0]).map((key) => lru.set(key, params[0][key], params[1])); | ||
} | ||
funcs.mSet(lru, params); | ||
sendResponse({ value: true }); | ||
@@ -158,5 +177,3 @@ break; | ||
case 'mDel': { | ||
if (params[0] && params[0] instanceof Array) { | ||
params[0].map((key) => lru.del(key)); | ||
} | ||
funcs.mDel(lru, params); | ||
sendResponse({ value: true }); | ||
@@ -272,18 +289,11 @@ break; | ||
case 'mGet': { | ||
const mGetValues = {}; | ||
if (funcArgs[0] && funcArgs[0] instanceof Array) { | ||
funcArgs[0].map((key) => (mGetValues[key] = lru.get(key))); | ||
} | ||
const mGetValues = funcs.mGet(lru, funcArgs); | ||
return Promise.resolve(mGetValues); | ||
} | ||
case 'mSet': { | ||
if (funcArgs[0] && funcArgs[0] instanceof Object) { | ||
Object.keys(funcArgs[0]).map((key) => lru.set(key, funcArgs[0][key], funcArgs[1])); | ||
} | ||
funcs.mSet(lru, funcArgs); | ||
return Promise.resolve(true); | ||
} | ||
case 'mDel': { | ||
if (funcArgs[0] && funcArgs[0] instanceof Array) { | ||
funcArgs[0].map((key) => lru.del(key)); | ||
} | ||
funcs.mDel(lru, funcArgs); | ||
return Promise.resolve(true); | ||
@@ -355,11 +365,11 @@ } | ||
const objs = {}; | ||
return Promise.all( | ||
Object.keys(pairs).map((key) => Promise.resolve((objs[key] = JSON.parse(pairs[key])))) | ||
).then(() => Promise.resolve(objs)); | ||
return funcs | ||
.mapObjects(pairs, objs, 'parse') | ||
.then(() => Promise.resolve(objs)); | ||
}), | ||
mSetObjects: (pairs, maxAge) => { | ||
const objs = {}; | ||
return Promise.all( | ||
Object.keys(pairs).map((key) => Promise.resolve((objs[key] = JSON.stringify(pairs[key])))) | ||
).then(() => promiseTo('mSet', objs, maxAge)); | ||
return funcs | ||
.mapObjects(pairs, objs, 'stringify') | ||
.then(() => promiseTo('mSet', objs, maxAge)); | ||
}, | ||
@@ -366,0 +376,0 @@ mDel: (keys) => promiseTo('mDel', keys), |
{ | ||
"name": "lru-cache-for-clusters-as-promised", | ||
"version": "1.5.9", | ||
"version": "1.5.10", | ||
"description": "LRU Cache that is safe for clusters", | ||
@@ -5,0 +5,0 @@ "main": "./lru-cache-for-clusters-as-promised.js", |
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
115892
1071