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

zcache

Package Overview
Dependencies
Maintainers
7
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.2.8 to 0.2.9

4

lib/CacheInstance.js

@@ -160,7 +160,7 @@ var events = require('events')

for (var i = 0; i < data.length; i++) {
if (typeof data[i] !== 'undefined' && data[i] !== null) self._hitCount += 1
if (typeof data[i] !== 'undefined') self._hitCount += 1
}
} else {
self._accessCount += 1
if (typeof data !== 'undefined' && data !== null) self._hitCount += 1
if (typeof data !== 'undefined') self._hitCount += 1
}

@@ -167,0 +167,0 @@ return data

@@ -117,2 +117,4 @@ // Copyright 2013 The Obvious Corporation.

this._hitCount += 1
} else {
ret[i] = undefined
}

@@ -125,2 +127,4 @@ }

InMemoryCache.prototype.set = function (key, val, maxAgeMs) {
if ((maxAgeMs === undefined || maxAgeMs <= 0) && !this._maxAgeOverride) throw new Error('maxAge must either be positive or overriden with a positive overrideMaxAgeMs')
this._expireAt[key] = Date.now() + (this._maxAgeOverride || maxAgeMs )

@@ -127,0 +131,0 @@ return this._data[key] = val

@@ -85,2 +85,13 @@ var redis = require('redis')

return deferred.promise
.then(function (vals) {
// This function post-processes values from Redis client to
// make cache miss result consistent with the API.
//
// Redis client returns null objects for cache misses, and we
// turn them into undefined.
for (var i = 0; i < vals.length; i++) {
if (null === vals[i]) vals[i] = undefined
}
return vals
})
.then(this.updateCount())

@@ -87,0 +98,0 @@ .then(this.updateStats('mget'))

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

.then(function (itemIndex, data) {
if (data == undefined) return undefined
if (data === undefined) return undefined
for (var k = 0; k < data.length; k++) res[itemIndex + k] = data[k]

@@ -101,0 +101,0 @@ }.bind(null, startOfHole)))

{
"name": "zcache",
"description": "AWS zone-aware multi-layer cache",
"version": "0.2.8",
"version": "0.2.9",
"homepage": "https://github.com/Obvious/zcache",

@@ -6,0 +6,0 @@ "authors": [

@@ -30,2 +30,11 @@ var zcache = require('../index')

exports.testCacheSetImproperMaxAge = function (test) {
var client = this
test.throws(function () {
client.cI.set('foo', 'bar')
})
test.done()
}
exports.testCacheOverrideMaxAgeMs = function (test) {

@@ -38,3 +47,3 @@ this.cI.overrideMaxAgeMs(1) // super short

.then(function (data) {
test.equal(data, undefined, 'foo should have expired by now')
test.deepEqual(data, undefined, 'foo should have expired by now')
test.done()

@@ -62,3 +71,3 @@ })

setTimeout(function () {
test.equal(this.cI._data['foo'], undefined, 'foo should not be in the cache')
test.deepEqual(this.cI._data['foo'], undefined, 'foo should not be in the cache')
test.done()

@@ -77,3 +86,3 @@ }.bind(this), 3001)

.then(function (data) {
test.equal(data, undefined, 'foo should still be in the cache')
test.deepEqual(data, undefined, 'foo should still be in the cache')
test.equal(1, self.cI.getAccessCount(), 'The number of accesses is 1')

@@ -99,6 +108,14 @@ test.equal(0, self.cI.getHitCount(), 'The number of hits is 0 - the cache entry has expired')

exports.testCacheGetundefined = function (test) {
this.cI.get('foo')
.then(function (data) {
test.deepEqual(data, undefined, 'foo should have returned undefined')
test.done()
})
}
exports.testCacheDel = function (test) {
this.cI.set('foo', 1, 1000)
this.cI.del('foo')
test.equal(this.cI._data['foo'], undefined, 'foo should have been deleted')
test.deepEqual(this.cI._data['foo'], undefined, 'foo should have been deleted')
test.done()

@@ -114,3 +131,3 @@ }

this.cI.mset(sampleKeys)
this.cI.mset(sampleKeys, 1000)
test.equal(this.cI._data['a'], 1, 'a should be 1')

@@ -128,3 +145,3 @@ test.equal(this.cI._data['b'], 2, 'b should be 2')

.then(function (keys) {
if (keys.length != 3) test.fail('there should be 3 items returned')
test.equal(keys.length, 3, '3 items should have been returned')
test.equal(keys[0], 1, 'a should be 1')

@@ -139,2 +156,24 @@ test.equal(keys[1], 2, 'b should be 2')

exports.testCacheMgetReturnsUndefined = function (test) {
this.cI.mget(['a'])
.then(function (results) {
test.equal(results.length, 1, '1 key should have been returned')
test.deepEqual(results[0], undefined, 'the first result should be undefined')
test.done()
})
}
exports.testCacheMgetReturnUndefinedAndValid = function (test) {
this.cI.set('foo', 'bar', 5000)
test.equal(this.cI._data['foo'], 'bar', 'bar should have been set')
this.cI.mget(['NON', 'foo'])
.then(function (results) {
test.equal(results.length, 2, '2 keys should have been returned')
test.deepEqual(results[0], undefined, 'NON should have returned undefined')
test.deepEqual(results[1], 'bar', 'foo should have returned bar')
test.done()
})
}
exports.testCacheMgetMissing = function (test) {

@@ -148,6 +187,7 @@ this.cI.setReaperInterval(1000)

self.cI.mget(['a', 'b', 'c'])
.then(function (keys) {
test.equal(keys[0], undefined, 'a should be undefined')
test.equal(keys[1], undefined, 'b should be undefined')
test.equal(keys[2], undefined, 'c should be undefined')
.then(function (results) {
test.equal(results.length, 3, '3 results should have been returned')
test.deepEqual(results[0], undefined, 'a should be undefined')
test.deepEqual(results[1], undefined, 'b should be undefined')
test.deepEqual(results[2], undefined, 'c should be undefined')
test.equal(3, self.cI.getAccessCount(), 'The number of accesses is 3')

@@ -154,0 +194,0 @@ test.equal(0, self.cI.getHitCount(), 'The number of hits is 0')

@@ -47,3 +47,3 @@ var zcache = require('../index')

.then(function (vals) {
test.equal(vals[0], null)
test.deepEqual(vals[0], undefined)
})

@@ -57,19 +57,23 @@ .then(function () {

value: '789'
}, {
// test negative caching
key: 'c',
value: null
}], 300000)
})
.then(function () {
return cacheInstance.mget(['a', 'b', 'c'])
return cacheInstance.mget(['a', 'b', 'c', 'd'])
})
.then(function (vals) {
test.equal(vals.length, 3, 'Should have precisely 3 results')
test.equal(vals[0], '456')
test.equal(vals[1], '789')
test.equal(vals[2], null)
test.equal(1, cacheInstance.getStats('set').count(), 'set() is called for once')
test.equal(1, cacheInstance.getStats('mset').count(), 'mset() is called for once')
test.equal(0, cacheInstance.getStats('get').count(), 'get() is not called')
test.equal(3, cacheInstance.getStats('mget').count(), 'mget() is called for three times')
test.equal(1, cacheInstance.getStats('del').count(), 'del() is call for once')
test.equal(5, cacheInstance.getAccessCount(), 'The number of cache access is 5')
test.equal(3, cacheInstance.getHitCount(), 'The number of cache hit is 3')
test.deepEqual(vals[2], 'null')
test.deepEqual(vals[3], undefined)
test.equal(cacheInstance.getStats('set').count(), 1, 'set() is called for once')
test.equal(cacheInstance.getStats('mset').count(), 1, 'mset() is called for once')
test.equal(cacheInstance.getStats('get').count(), 0, 'get() is not called')
test.equal(cacheInstance.getStats('mget').count(), 3, 'mget() is called for three times')
test.equal(cacheInstance.getStats('del').count(), 1, 'del() is call for once')
test.equal(cacheInstance.getAccessCount(), 6, 'The number of cache access is 6')
test.equal(cacheInstance.getHitCount(), 4, 'The number of cache hit is 4')
return cacheInstance.getServerInfo()

@@ -76,0 +80,0 @@ })

@@ -68,2 +68,11 @@ var zcache = require('../index')

testCacheMgetUndefinedMget: function (test) {
this.cacheInstance.mget(['foo', 'bar'])
.then(function (results) {
test.deepEqual(results[0], undefined, 'foo should be undefined')
test.deepEqual(results[1], undefined, 'bar should be undefined')
test.done()
})
},
testCacheMgetMultipleSingleHolesStagger: function (test) {

@@ -180,3 +189,3 @@ this.cacheInstance.set('one', 'one', 10000)

testCacheMsetStagger: function (test) {
this.cacheInstance.mset([{key: 'foo', value: 'bar'}, {key: 'fah', value: 'bah'}])
this.cacheInstance.mset([{key: 'foo', value: 'bar'}, {key: 'fah', value: 'bah'}], 1000)

@@ -183,0 +192,0 @@ test.equal(this.memoryInstance1._data['foo'], 'bar', 'bar should be in memoryInstance1')

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