Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zcache

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

zcache - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

92

lib/CacheCluster.js

@@ -192,3 +192,3 @@ var poolModule = require('generic-pool')

}
var promises = []

@@ -202,23 +202,4 @@ for (var uri in servers) {

return Q.all(promises)
.then(function (results) {
var resultArr = Array(keys.length)
var resultPriorities = {}
for (var i = 0; i < results.length; i++) {
var serverResults = results[i]
var server = serverArr[i]
for (var j = 0; j < serverResults.length; j++) {
var key = server.keys[j]
var priority = server.priorities[j]
if (!resultPriorities[key] || priority < resultPriorities[key]) {
resultPriorities[key] = priority
for (var k = 0; k < keyIndexes[key].length; k++) {
resultArr[keyIndexes[key][k]] = serverResults[j]
}
}
}
}
return resultArr
})
.setContext({keys: keys, keyIndexes: keyIndexes, serverArr: serverArr})
.then(processMgetResults)
}

@@ -228,5 +209,3 @@

return this.mget([key])
.then(function (results) {
return results[0]
})
.then(returnFirstResult)
}

@@ -243,5 +222,3 @@

return Q.all(promises).then(function () {
return true
})
return Q.all(promises).then(returnTrue)
}

@@ -258,8 +235,61 @@

return Q.all(promises).then(function () {
return true
})
return Q.all(promises).then(returnTrue)
}
/**
* Iterate through all mget results and put them into an object
* based on the order of keys provided
*
* @param {Object} results [description]
* @param {{keys: Array.<string>, keyIndexes: Object, serverArr: Array.<Object>}} context information
* needed to put the results back into an array based on the key order originally provided
* @return {Array.<Object>} the results from the cache
*/
function processMgetResults(results, context) {
var keys = context.keys
var keyIndexes = context.keyIndexes
var serverArr = context.serverArr
var resultArr = Array(keys.length)
var resultPriorities = {}
for (var i = 0; i < results.length; i++) {
var serverResults = results[i]
var server = serverArr[i]
for (var j = 0; j < serverResults.length; j++) {
var key = server.keys[j]
var priority = server.priorities[j]
if (!resultPriorities[key] || priority < resultPriorities[key]) {
resultPriorities[key] = priority
for (var k = 0; k < keyIndexes[key].length; k++) {
resultArr[keyIndexes[key][k]] = serverResults[j]
}
}
}
}
return resultArr
}
/**
* Return the first result from a result set
* @param {Array.<Object>} results the results
* @return {Object} the cached result
*/
function returnFirstResult(results) {
return results[0]
}
/**
* Always return true
* @return {boolean} true!
*/
function returnTrue() {
return true
}
/**
* Always return an empty array
* @return {Array} an empty array
*/
function returnEmptyArr() {

@@ -266,0 +296,0 @@ return []

@@ -15,2 +15,3 @@ var poolModule = require('generic-pool')

this._bound_updatePoolStatus = this._updatePoolStatus.bind(this)
this._bound_releaseClient = this._releaseClient.bind(this)

@@ -94,42 +95,93 @@ opts = opts || {}

ConnectionPool.prototype._releaseClient = function (client) {
this._pool.release(client)
ConnectionPool.prototype._releaseClient = function (val, context) {
this._pool.release(context.client)
}
ConnectionPool.prototype._prepareReleaseClient = function (promise) {
promise.then(this._bound_releaseClient)
.fail(this._bound_releaseClient)
return promise
}
ConnectionPool.prototype.mget = function (keys) {
var self = this
return this._acquireClient()
.then(function (client) {
return client.mget(keys)
.fin(self._releaseClient.bind(self, client))
})
var promise = this._acquireClient()
.setContext({keys: keys})
.then(callMget)
return this._prepareReleaseClient(promise)
}
/**
* Call mget on a memcache client
*
* @param {Object} client the memcache client
* @param {Object} context the query context
* @return {Promise.<Array.<string>>} the cached response
*/
function callMget(client, context) {
context.client = client
return client.mget(context.keys)
}
ConnectionPool.prototype.get = function (key) {
var self = this
return this._acquireClient()
.then(function (client) {
return client.get(key)
.fin(self._releaseClient.bind(self, client))
})
var promise = this._acquireClient()
.setContext({key: key})
.then(callGet)
return this._prepareReleaseClient(promise)
}
/**
* Call get on a memcache client
*
* @param {Object} client the memcache client
* @param {Object} context the query context
* @return {Promise.<string>} the cached response
*/
function callGet(client, context) {
context.client = client
return client.get(context.key)
}
ConnectionPool.prototype.set = function (key, val, maxAgeMs) {
var self = this
return this._acquireClient()
.then(function (client) {
return client.set(key, val, maxAgeMs)
.fin(self._releaseClient.bind(self, client))
})
var promise = this._acquireClient()
.setContext({key: key, val: val, maxAgeMs: maxAgeMs})
.then(callSet)
return this._prepareReleaseClient(promise)
}
/**
* Call set on a memcache client
*
* @param {Object} client the memcache client
* @param {Object} context the query context
* @return {Promise.<string>} the cached response
*/
function callSet(client, context) {
context.client = client
return client.set(context.key, context.val, context.maxAgeMs)
}
ConnectionPool.prototype.del = function (key) {
var self = this
return this._acquireClient()
.then(function (client) {
return client.del(key)
.fin(self._releaseClient.bind(self, client))
})
var promise = this._acquireClient()
.setContext({key: key})
.then(callDel)
return this._prepareReleaseClient(promise)
}
/**
* Call delete on a memcache client
*
* @param {Object} client the memcache client
* @param {Object} context the query context
* @return {Promise.<string>} the cached response
*/
function callDel(client, context) {
context.client = client
return client.del(context.key)
}
module.exports = ConnectionPool

@@ -28,7 +28,3 @@ var redis = require('redis')

return deferred.promise
.fail(function (e) {
// if the cache set failed for some reason, warn but continue
context.logger.warn(e)
return true
})
.fail(warnOnError)
}

@@ -41,7 +37,3 @@

return deferred.promise
.fail(function (e) {
// if the cache set failed for some reason, warn but continue
context.logger.warn(e)
return true
})
.fail(warnOnError)
}

@@ -51,5 +43,3 @@

return this.mget([key])
.then(function (results) {
return results[0]
})
.then(returnFirstResult)
}

@@ -107,2 +97,23 @@

/**
* Warn when an error occurs but continue
*
* @param {Error} e the error
* @return {boolean} true
*/
function warnOnError(e) {
// if the cache set failed for some reason, warn but continue
console.warn(e)
return true
}
/**
* Return the first result from a result set
* @param {Array.<Object>} results the results
* @return {Object} the cached result
*/
function returnFirstResult(results) {
return results[0]
}
module.exports = RedisConnection

@@ -98,5 +98,3 @@ var util = require('util')

return Q.all(promises)
.then(function () {
return true
})
.then(returnTrue)
}

@@ -113,7 +111,13 @@

return Q.all(promises)
.then(function () {
return true
})
.then(returnTrue)
}
/**
* Always return true
* @return {boolean} true!
*/
function returnTrue() {
return true
}
module.exports = RedundantCacheGroup
{
"name": "zcache"
, "description": "AWS zone-aware caching"
, "version": "0.1.4"
, "version": "0.1.5"
, "homepage": "https://github.com/azulus/zcache"

@@ -21,3 +21,3 @@ , "authors": [

"generic-pool": "2.0.3",
"kew": "*",
"kew": "0.1.3",
"redis": "0.8.2"

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