Comparing version 0.1.0 to 0.1.1
@@ -7,3 +7,3 @@ var memc = require('node-memcache-parser-obvfork').client | ||
function MemcacheConnection(host, port) { | ||
function MemcacheConnection(host, port, encoding) { | ||
CacheInstance.call(this) | ||
@@ -13,2 +13,3 @@ | ||
this._port = port | ||
this._encoding = encoding | ||
this._connection = new memc.Connection() | ||
@@ -29,2 +30,3 @@ this._isAvailable = false | ||
var defer = Q.defer() | ||
if (this._encoding) val = new Buffer(val).toString(this._encoding) | ||
this._connection.set(key, val, 0x01, Math.floor(maxAgeMs ? maxAgeMs / 1000 : 86400), function (message) { | ||
@@ -37,6 +39,16 @@ defer.resolve(true) | ||
MemcacheConnection.prototype.get = function (key) { | ||
var self = this | ||
var defer = Q.defer() | ||
this._connection.get(key, function (message) { | ||
defer.resolve(message.header.status == memc.constants.status.NO_ERROR && message.header.bodylen ? message.body.toString('utf8') : undefined) | ||
if (message.header.status != memc.constants.status.NO_ERROR || !message.header.bodylen) { | ||
defer.resolve(undefined) | ||
return | ||
} | ||
var bodyBuffer = message.body | ||
if (self._encoding) bodyBuffer = new Buffer(bodyBuffer.toString(self._encoding), self._encoding) | ||
defer.resolve(bodyBuffer.toString('utf8')) | ||
}) | ||
return defer.promise | ||
@@ -43,0 +55,0 @@ } |
{ | ||
"name": "zcache" | ||
, "description": "AWS zone-aware caching" | ||
, "version": "0.1.0" | ||
, "version": "0.1.1" | ||
, "homepage": "https://github.com/azulus/zcache" | ||
@@ -6,0 +6,0 @@ , "authors": [ |
@@ -61,2 +61,61 @@ var zcache = require('../index') | ||
cacheInstance.connect() | ||
} | ||
exports.testMemcacheConnectionBase64 = function (test) { | ||
var cacheInstance = new zcache.MemcacheConnection("localhost", 11212, 'base64') | ||
test.equal(cacheInstance.isAvailable(), false, "Connection should not be available") | ||
cacheInstance.on('connect', function () { | ||
cacheInstance.removeAllListeners('connect') | ||
test.equal(cacheInstance.isAvailable(), true, "Connection should be available") | ||
cacheInstance.set('abc', '123', 300000) | ||
.then(function () { | ||
cacheInstance.disconnect() | ||
// wait to ensure reconnection | ||
var defer = Q.defer() | ||
setTimeout(function () { | ||
defer.resolve(true) | ||
}, 200) | ||
return defer.promise | ||
}) | ||
.then(function () { | ||
cacheInstance.connect() | ||
// wait to ensure reconnection | ||
var defer = Q.defer() | ||
setTimeout(function () { | ||
defer.resolve(true) | ||
}, 200) | ||
return defer.promise | ||
}) | ||
.then(function () { | ||
return cacheInstance.mget(['abc']) | ||
}) | ||
.then(function (vals) { | ||
test.equal(vals[0], '123') | ||
return cacheInstance.del('abc') | ||
}) | ||
.then(function () { | ||
return cacheInstance.mget(['abc']) | ||
}) | ||
.then(function (vals) { | ||
test.equal(vals[0], undefined) | ||
cacheInstance.destroy() | ||
}) | ||
.fail(function (e) { | ||
console.error(e) | ||
test.fail(e.message) | ||
test.done() | ||
}) | ||
}) | ||
cacheInstance.on('destroy', function () { | ||
test.equal(cacheInstance.isAvailable(), false, "Connection should not be available") | ||
test.done() | ||
}) | ||
cacheInstance.connect() | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
63629
1361
1