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.0 to 0.1.1

16

lib/MemcacheConnection.js

@@ -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 @@ }

2

package.json
{
"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()
}
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