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.0.2 to 0.0.3

11

lib/CacheCluster.js
var CacheServer = require('./CacheServer')
var ConsistentHasher = require('./ConsistentHasher')
var Q = require('kew')

@@ -30,3 +29,8 @@ var common = require('./common')

this._servers[uri].setCapacity(capacity, msPerCapacityUnit)
try {
this._servers[uri].setCapacity(capacity, msPerCapacityUnit)
} catch (e) {
console.error(e.stack)
}
}

@@ -62,3 +66,2 @@

CacheCluster.prototype.getStats = function (key) {
var self = this
var stats = {}

@@ -71,3 +74,3 @@ var promises = []

var defer = Q.defer()
self._servers[uri].getClient().stats(key, defer.makeNodeResolver())
this._servers[uri].getClient().stats(key, defer.makeNodeResolver())
promises.push(defer.promise.then(function (data) {

@@ -74,0 +77,0 @@ stats[uri] = data

@@ -28,6 +28,10 @@ var Q = require('kew')

for (i = 0; i < clients.length; i++){
deferreds.push(Q.defer())
clients[i].get(key, deferreds[i].makeNodeResolver())
var defer = Q.defer()
clients[i].get(key, defer.makeNodeResolver())
deferreds.push(defer.promise.fail(function (e) {
return undefined
}))
}
if (!deferreds.length) return Q.resolve(undefined)
return deferreds.shift().promise.then(getFirstResponse.bind(null, deferreds))

@@ -49,4 +53,7 @@ }

var defer = Q.defer()
clients[i].set(key, val, defer.makeNodeResolver(), lifetime)
promises.push(defer.promise)
clients[i].set(key, val, lifetime || 0, defer.makeNodeResolver())
promises.push(defer.promise.fail(function (e) {
return true
}))
}

@@ -64,3 +71,3 @@

for (var key in this._clusters) {
promises.push(this._clusters[key].getStats(stats).then(function (data) {
promises.push(this._clusters[key].getStats().then(function (data) {
for (var key in data) {

@@ -67,0 +74,0 @@ allStats[key] = data[key]

var events = require('events')
var memcache = require('memcache')
var Memcached = require('memcached')
var util = require('util')

@@ -9,27 +9,29 @@

this._uri = uri
var uriParts = this._uri.split(':')
this._status = common.SERVER_STATUS.DISCONNECTED
this._host = uriParts[0]
this._port = uriParts[1]
clientCtor = clientCtor || memcache.Client
this._client = new clientCtor(this._port, this._host)
clientCtor = clientCtor || Memcached
this._client = new clientCtor(this._uri, {
timeout: 20,
retries: 0
})
this._currentCapacity = 0
this._targetCapacity = 0
this._status = common.SERVER_STATUS.DISCONNECTED
this._connectionTimer = null
this._connectionIntervalMs = 0
this._capacityTimer = null
this._client.on('connect', this._bound_onConnect = this._onConnect.bind(this))
this._client.on('close', this._bound_onClose = this._onClose.bind(this))
this._client.on('timeout', this._bound_onTimeout = this._onTimeout.bind(this))
this._client.on('error', this._bound_onError = this._onError.bind(this))
this._scheduleConnect()
this.checkStatus()
this._statusInterval = setInterval(this.checkStatus.bind(this), 5000)
}
util.inherits(CacheServer, events.EventEmitter)
CacheServer.prototype.checkStatus = function () {
if (this._status === common.SERVER_STATUS.DESTROYED) return
var self = this
this._client.version(function (err, data) {
self._status = err ? common.SERVER_STATUS.DISCONNECTED : common.SERVER_STATUS.CONNECTED
})
}
/**

@@ -39,9 +41,7 @@ * Shut down this server client

CacheServer.prototype.close = function () {
this._client.removeListener('connect', this._bound_onConnect)
this._client.removeListener('close', this._bound_onClose)
this._client.removeListener('timeout', this._bound_onTimeout)
this._client.removeListener('error', this._bound_onError)
if (this._statusInterval) clearInterval(this._statusInterval)
this._status = common.SERVER_STATUS.DESTROYED
this._client.close()
this._client.end()
}

@@ -116,67 +116,2 @@

/**
* Schedule the next connection attempt for a memcache client
*
* @param {string} host colon-delimited host with port
*/
CacheServer.prototype._scheduleConnect = function () {
if (this._connectionTimer || this._status == common.SERVER_STATUS.DESTROYED) return
var attemptMs
var self = this
if (!this._connectionIntervalMs) {
attemptMs = 1
this._connectionIntervalMs = common.MIN_BACKOFF
} else {
attemptMs = this._connectionIntervalMs
if (this._connectionIntervalMs < common.MAX_BACKOFF) {
this._connectionIntervalMs *= common.BACKOFF_MULTIPLIER
if (this._connectionIntervalMs > common.MAX_BACKOFF) this._connectionIntervalMs = common.MAX_BACKOFF
}
}
this.emit('connectionAttempt', attemptMs)
self._connectionTimer = setTimeout(function () {
delete self._connectionTimer
self._client.connect()
}, attemptMs)
}
/**
* Handle a timed out client
*/
CacheServer.prototype._onTimeout = function () {
this._status = common.SERVER_STATUS.TIMED_OUT
this.emit('timeout')
this._client.close()
this._scheduleConnect()
}
/**
* Handle an erroring client
*/
CacheServer.prototype._onError = function (e) {
this.emit('error', e)
this._scheduleConnect()
}
/**
* Handle a closed client
*/
CacheServer.prototype._onClose = function () {
this.emit('close')
this._status = common.SERVER_STATUS.DISCONNECTED
this._scheduleConnect()
}
/**
* Handle a connected client
*/
CacheServer.prototype._onConnect = function () {
this._connectionIntervalMs = 0
this._status = common.SERVER_STATUS.CONNECTED
this.emit('connect')
}
module.exports = CacheServer

@@ -17,3 +17,3 @@ var events = require('events')

FakeMemcache.prototype.close = function () {
FakeMemcache.prototype.end = function () {
this.emit('close')

@@ -30,3 +30,7 @@ }

FakeMemcache.prototype.set = function (key, val, callback, lifetimeMs) {
FakeMemcache.prototype.version = function (callback) {
callback(null, {})
}
FakeMemcache.prototype.set = function (key, val, lifetimeMs, callback) {
this._data[key] = val

@@ -33,0 +37,0 @@ callback(null, true)

{
"name": "zcache"
, "description": "AWS zone-aware caching"
, "version": "0.0.2"
, "version": "0.0.3"
, "homepage": "https://github.com/azulus/zcache"

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

, "dependencies": {
"memcache": "*"
"memcached": "*"
}

@@ -22,0 +22,0 @@ , "devDependencies": {

@@ -83,4 +83,8 @@ var CacheCluster = require('../lib/CacheCluster')

test.equal(data, undefined, "Should get undefined again")
primaryCluster.setServerCapacity('localhost:11212', 0)
primaryCluster.setServerCapacity('localhost:11213', 0)
secondaryCluster.setServerCapacity('localhost:11214', 0)
secondaryCluster.setServerCapacity('localhost:11215', 0)
test.done()
})
}
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