Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

npm preparations

- Removed utils. Moved to node_cache
- changed return formats of get, set and del
- modified package
- fixed tests to new return format
  • Loading branch information...
commit 84be8be73cdae2c0d623f4f894c0008e6ba9ea7a 1 parent 5681bbd
@mpneuried mpneuried authored
View
1  index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/node_cache');
View
69 lib/node_cache.coffee
@@ -1,4 +1,19 @@
-module.exports = class VariableCache
+_ = require( "underscore" )
+
+# configure the time method
+# define options and the sequential multiplicators
+_timeConfig =
+ types: [ "ms", "s", "m", "h", "d" ]
+ multiConfig: [ 1, 1000, 60, 60, 24 ]
+# calculate the final multiplacatos
+_timeConfig.multi = _.reduce( _timeConfig.multiConfig, ( v1, v2, idx, ar )->
+ v1.push ( v1[ idx-1 ] or 1 ) * v2
+ v1
+, [] )
+
+
+# generate superclass
+module.exports = class NodeCache
constructor: ( @options = {} )->
# container for cached dtaa
@@ -41,11 +56,13 @@ module.exports = class VariableCache
# get data and incremet stats
if @data[ key ]? and @_check( key, @data[ key ] )
@stats.hits++
- cb( null, @_unwrap( @data[ key ] ) )
+ oRet = {}
+ oRet[ key ] = @_unwrap( @data[ key ] )
+ cb( null, oRet )
else
# if not found return a error
@stats.misses++
- @_error( 'not-found', method: "get", cb )
+ cb( null, {} )
return
# ## set
@@ -128,7 +145,7 @@ module.exports = class VariableCache
else
# if the key has not been found return an error
@stats.misses++
- @_error( 'not-found', method: "del", cb )
+ cb( null, true )
return
# ## getStats
@@ -186,7 +203,7 @@ module.exports = class VariableCache
if ttl is 0
livetime = 0
else if ttl
- livetime = new Date().getTime() + utils.getMilliSeconds( ttl )
+ livetime = new Date().getTime() + @_getMilliSeconds( ttl )
else
livetime = @options.stdTTL
@@ -242,4 +259,44 @@ module.exports = class VariableCache
return
else
# if no callbach is defined return the error object
- error
+ error
+
+ # ## getMilliSeconds
+ #
+ # get the milliseconds form a String like "5s" or "3h". Format is "[ time ][ type ]"
+ # Possible types are [ "ms", "s", "m", "h", "d" ]
+ #
+ # **Parameters:**
+ #
+ # * `time` ( String|Number ): the time to convert
+ #
+ # **Returns:**
+ #
+ # ( Number ): timespan in miliseconds
+ #
+ # **Example:**
+ #
+ # utils.getMilliSeconds( 100 ) # 100
+ # utils.getMilliSeconds( "100" ) # 100
+ # utils.getMilliSeconds( "5s" ) # 5000
+ # utils.getMilliSeconds( "3m" ) # 180000
+ # utils.getMilliSeconds( "3d" ) # 259200000
+ # utils.getMilliSeconds( "aaa" ) # null
+ #
+ _getMilliSeconds: ( time )=>
+ iType = -1
+ if _.isString( time )
+ # slice the input to time and type
+ type = time.replace( /\d+/gi, '' )
+ time = parseInt( time.replace( /\D+/gi, '' ), 10 )
+
+ # find the type
+ iType = _timeConfig.types.indexOf( type )
+
+ # multiplicate the time
+ if iType >= 0
+ time * _timeConfig.multi[ iType ]
+ else if isNaN( time )
+ null
+ else
+ time
View
71 lib/node_cache.js
@@ -1,9 +1,19 @@
(function() {
- var VariableCache;
+ var NodeCache, _, _timeConfig;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
- module.exports = VariableCache = (function() {
- function VariableCache(options) {
+ _ = require("underscore");
+ _timeConfig = {
+ types: ["ms", "s", "m", "h", "d"],
+ multiConfig: [1, 1000, 60, 60, 24]
+ };
+ _timeConfig.multi = _.reduce(_timeConfig.multiConfig, function(v1, v2, idx, ar) {
+ v1.push((v1[idx - 1] || 1) * v2);
+ return v1;
+ }, []);
+ module.exports = NodeCache = (function() {
+ function NodeCache(options) {
this.options = options != null ? options : {};
+ this._getMilliSeconds = __bind(this._getMilliSeconds, this);
this._error = __bind(this._error, this);
this._check = __bind(this._check, this);
this._getValLength = __bind(this._getValLength, this);
@@ -29,18 +39,19 @@
vsize: 0
};
}
- VariableCache.prototype.get = function(key, cb) {
+ NodeCache.prototype.get = function(key, cb) {
+ var oRet;
if ((this.data[key] != null) && this._check(key, this.data[key])) {
this.stats.hits++;
- cb(null, this._unwrap(this.data[key]));
+ oRet = {};
+ oRet[key] = this._unwrap(this.data[key]);
+ cb(null, oRet);
} else {
this.stats.misses++;
- this._error('not-found', {
- method: "get"
- }, cb);
+ cb(null, {});
}
};
- VariableCache.prototype.set = function(key, value, ttl, cb) {
+ NodeCache.prototype.set = function(key, value, ttl, cb) {
var existend;
existend = false;
if (this.options.forceString && !_.isString(value)) {
@@ -62,7 +73,7 @@
}
cb(null, true);
};
- VariableCache.prototype.del = function(key, cb) {
+ NodeCache.prototype.del = function(key, cb) {
if (cb == null) {
cb = function() {};
}
@@ -74,15 +85,13 @@
cb(null, true);
} else {
this.stats.misses++;
- this._error('not-found', {
- method: "del"
- }, cb);
+ cb(null, true);
}
};
- VariableCache.prototype.getStats = function() {
+ NodeCache.prototype.getStats = function() {
return this.stats;
};
- VariableCache.prototype.checkData = function() {
+ NodeCache.prototype.checkData = function() {
var key, value, _ref;
_ref = this.data;
for (key in _ref) {
@@ -90,13 +99,13 @@
this._check(key, vData);
}
};
- VariableCache.prototype._wrap = function(value, ttl) {
+ NodeCache.prototype._wrap = function(value, ttl) {
var livetime, oReturn;
livetime = 0;
if (ttl === 0) {
livetime = 0;
} else if (ttl) {
- livetime = new Date().getTime() + utils.getMilliSeconds(ttl);
+ livetime = new Date().getTime() + this._getMilliSeconds(ttl);
} else {
livetime = this.options.stdTTL;
}
@@ -105,13 +114,13 @@
v: value
};
};
- VariableCache.prototype._unwrap = function(value) {
+ NodeCache.prototype._unwrap = function(value) {
return value.v || null;
};
- VariableCache.prototype._getKeyLength = function(key) {
+ NodeCache.prototype._getKeyLength = function(key) {
return key.length;
};
- VariableCache.prototype._getValLength = function(value) {
+ NodeCache.prototype._getValLength = function(value) {
if (_.isString(value)) {
return value.length;
} else if (this.options.forceString) {
@@ -122,7 +131,7 @@
return this.options.objectValueSize * _.size(value);
}
};
- VariableCache.prototype._check = function(key, data) {
+ NodeCache.prototype._check = function(key, data) {
var now;
now = new Date().getTime();
if (data.t < now && data.t !== 0) {
@@ -132,7 +141,7 @@
return true;
}
};
- VariableCache.prototype._error = function(type, data, cb) {
+ NodeCache.prototype._error = function(type, data, cb) {
var error;
if (data == null) {
data = {};
@@ -148,6 +157,22 @@
return error;
}
};
- return VariableCache;
+ NodeCache.prototype._getMilliSeconds = function(time) {
+ var iType, type;
+ iType = -1;
+ if (_.isString(time)) {
+ type = time.replace(/\d+/gi, '');
+ time = parseInt(time.replace(/\D+/gi, ''), 10);
+ iType = _timeConfig.types.indexOf(type);
+ }
+ if (iType >= 0) {
+ return time * _timeConfig.multi[iType];
+ } else if (isNaN(time)) {
+ return null;
+ } else {
+ return time;
+ }
+ };
+ return NodeCache;
})();
}).call(this);
View
51 lib/utils.coffee
@@ -1,51 +0,0 @@
-# configure the time method
-# define options and the sequential multiplicators
-_timeConfig =
- types: [ "ms", "s", "m", "h", "d" ]
- multiConfig: [ 1, 1000, 60, 60, 24 ]
-# calculate the final multiplacatos
-_timeConfig.multi = _.reduce( _timeConfig.multiConfig, ( v1, v2, idx, ar )->
- v1.push ( v1[ idx-1 ] or 1 ) * v2
- v1
-, [] )
-
-module.exports =
- # ## getMilliSeconds
- #
- # get the milliseconds form a String like "5s" or "3h". Format is "[ time ][ type ]"
- # Possible types are [ "ms", "s", "m", "h", "d" ]
- #
- # **Parameters:**
- #
- # * `time` ( String|Number ): the time to convert
- #
- # **Returns:**
- #
- # ( Number ): timespan in miliseconds
- #
- # **Example:**
- #
- # utils.getMilliSeconds( 100 ) # 100
- # utils.getMilliSeconds( "100" ) # 100
- # utils.getMilliSeconds( "5s" ) # 5000
- # utils.getMilliSeconds( "3m" ) # 180000
- # utils.getMilliSeconds( "3d" ) # 259200000
- # utils.getMilliSeconds( "aaa" ) # null
- #
- getMilliSeconds: ( time )=>
- iType = -1
- if _.isString( time )
- # slice the input to time and type
- type = time.replace( /\d+/gi, '' )
- time = parseInt( time.replace( /\D+/gi, '' ), 10 )
-
- # find the type
- iType = _timeConfig.types.indexOf( type )
-
- # multiplicate the time
- if iType >= 0
- time * _timeConfig.multi[ iType ]
- else if isNaN( time )
- null
- else
- time
View
30 lib/utils.js
@@ -1,30 +0,0 @@
-(function() {
- var _timeConfig;
- var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
- _timeConfig = {
- types: ["ms", "s", "m", "h", "d"],
- multiConfig: [1, 1000, 60, 60, 24]
- };
- _timeConfig.multi = _.reduce(_timeConfig.multiConfig, function(v1, v2, idx, ar) {
- v1.push((v1[idx - 1] || 1) * v2);
- return v1;
- }, []);
- module.exports = {
- getMilliSeconds: __bind(function(time) {
- var iType, type;
- iType = -1;
- if (_.isString(time)) {
- type = time.replace(/\d+/gi, '');
- time = parseInt(time.replace(/\D+/gi, ''), 10);
- iType = _timeConfig.types.indexOf(type);
- }
- if (iType >= 0) {
- return time * _timeConfig.multi[iType];
- } else if (isNaN(time)) {
- return null;
- } else {
- return time;
- }
- }, this)
- };
-}).call(this);
View
34 package.json
@@ -1,19 +1,19 @@
{
- "author": "mpneuried <mp@tcs.de>",
- "name": "nodecache",
- "description": "a simple node internal caching module",
- "version": "0.0.1",
- "repository": {
- "type": "git",
- "url": "git://github.com/tcs-de/nodecache.git"
- },
- "engines": {
- "node": "~0.4.*"
- },
- "dependencies": {
- "underscore": ">= 1.1.7"
- },
- "devDependencies": {
- "expresso": ">= 0.9.2"
- },
+ "name": "node-cache",
+ "description": "A simple node internal caching module",
+ "keywords": [ "cache", "local", "variable" ],
+ "version": "0.1.1",
+ "author": "tcs-de <github@tcs.de>",
+ "main": "./index.js",
+ "homepage": "https://github.com/tcs-de/nodecache",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/tcs-de/nodecache.git"
+ },
+ "engines": {
+ "node": ">= 0.4.6"
+ },
+ "dependencies": {
+ "underscore": ">= 1.1.7"
+ }
}
View
151 test/node_cache-test.coffee
@@ -1,6 +1,5 @@
# define runtime environment
-root._ = require("../node_modules/underscore")
-root.utils = require( "../lib/utils" )
+_ = require( "underscore" )
VCache = require "../lib/node_cache"
localCache = new VCache( stdTTL: '15m' )
@@ -27,19 +26,76 @@ ks = []
module.exports =
"general": (beforeExit, assert) ->
- done = false
+ n = 0
+ start = _.clone( localCache.getStats() )
+
value = randomString( 100 )
+ value2 = randomString( 100 )
key = randomString( 10 )
+
+ # test insert
localCache.set key, value, 0, ( err, res )->
assert.isNull( err, err )
+ n++
+
+ # check stats
+ assert.equal 1, localCache.getStats().keys - start.keys
+
+ # try to get
localCache.get key, ( err, res )->
- done = true
- assert.equal value, res
- console.log( "general stats:", localCache.getStats() )
+ n++
+ # generate a predicted value
+ pred = {}
+ pred[ key ] = value
+ assert.eql pred, res
+
+ # get an undefined key
+ localCache.get "xxx", ( err, res )->
+ n++
+ assert.isNull( err, err )
+ assert.eql {}, res
+
+ # try to delete an undefined key
+ localCache.del "xxx", ( err, res )->
+ n++
+ assert.isNull( err, err )
+ assert.ok res
+
+ # test update
+ localCache.set key, value2, 0, ( err, res )->
+ n++
+ assert.isNull( err, err )
+ assert.ok( res, err )
+
+ # check update
+ localCache.get key, ( err, res )->
+ n++
+ # generate a predicted value
+ pred = {}
+ pred[ key ] = value2
+ assert.eql pred, res
+
+ # check if stats didn't changed
+ assert.equal 1, localCache.getStats().keys - start.keys
+
+ # try to delete the defined key
+ localCache.del key, ( err, res )->
+ n++
+ assert.isNull( err, err )
+ assert.ok res
+
+ # check stats
+ assert.equal 0, localCache.getStats().keys - start.keys
+
+ # try to get the deleted key
+ localCache.get key, ( err, res )->
+ n++
+ assert.isNull( err, err )
+ assert.eql {}, res
beforeExit ->
- assert.equal( true, done, "not exited" )
+ assert.equal( 8, n, "not exited" )
"many": (beforeExit, assert) ->
n = 0
@@ -62,7 +118,9 @@ module.exports =
for key in ks
localCache.get key, ( err, res )->
n++
- assert.equal val, res
+ pred = {}
+ pred[ key ] = val
+ assert.eql pred, res
console.log( "TIME-GET:", new Date().getTime() - time )
console.log( "MANY STATS:", localCache.getStats() )
@@ -76,19 +134,28 @@ module.exports =
n = 0
count = 10000
startKeys = localCache.getStats().keys
+
+ # test deletes
+ for i in [1..count]
+ ri = Math.floor(Math.random() * vs.length)
+ localCache.del ks[ i ], ( err, success )->
+ n++
+ assert.isNull( err, err )
+ assert.ok( success )
+
for i in [1..count]
ri = Math.floor(Math.random() * vs.length)
localCache.del ks[ i ], ( err, success )->
n++
assert.ok( success )
assert.isNull( err, err )
-
- console.log( "DELETE STATS:", localCache.getStats() )
- assert.equal( localCache.getStats().keys, startKeys - n )
+
+ # check stats for only a single deletion
+ assert.equal( localCache.getStats().keys, startKeys - count )
beforeExit ->
-
- assert.equal( n, count)
+ # check successfull runs
+ assert.equal( n, count * 2)
"ttl": (beforeExit, assert) ->
val = randomString( 20 )
@@ -96,87 +163,103 @@ module.exports =
key2 = randomString( 7 )
n = 0
+ # set a key with ttl
localCache.set key, val, 500, ( err, res )->
assert.isNull( err, err )
assert.ok( res )
+
+ # check the key immediately
localCache.get key, ( err, res )->
assert.isNull( err, err )
- assert.equal( val, res )
-
+ pred = {}
+ pred[ key ] = val
+ assert.eql( pred, res )
+
+ # set another key
localCache.set key2, val, 800, ( err, res )->
assert.isNull( err, err )
assert.ok( res )
+
+ # check the key immediately
localCache.get key2, ( err, res )->
assert.isNull( err, err )
- assert.equal( val, res )
+ pred = {}
+ pred[ key2 ] = val
+ assert.eql( pred, res )
+ # check key before lifetime end
setTimeout( ->
++n;
localCache.get key, ( err, res )->
assert.isNull( err, err )
- assert.equal( val, res )
+ pred = {}
+ pred[ key ] = val
+ assert.eql( pred, res )
, 400 )
+ # check key after lifetime end
setTimeout( ->
++n;
localCache.get key, ( err, res )->
- assert.isNull( res, res )
- assert.equal( 'not-found', err.errorcode )
+ assert.isNull( err, err )
+ assert.eql( {}, res )
, 600 )
+ # check second key before lifetime end
setTimeout( ->
++n;
localCache.get key2, ( err, res )->
assert.isNull( err, err )
- assert.equal( val, res )
+ pred = {}
+ pred[ key2 ] = val
+ assert.eql( pred, res )
+ assert.eql( pred, res )
, 600 )
-
- setTimeout( ->
- console.log( "TTL STATS:", localCache.getStats() )
- , 700 )
"stats": (beforeExit, assert) ->
n = 0
start = _.clone( localCache.getStats() )
count = 5
keys = []
+ vals = []
# add count`*2 elements
for i in [1..count*2]
key = randomString( 7 )
val = randomString( 50 )
keys.push key
+ vals.push val
localCache.set key, val, 0, ( err, success )->
n++
- assert.ok( success )
assert.isNull( err, err )
+ assert.ok( success )
# get and remove `count` elements
for i in [1..count]
- key = randomString( 7 )
- val = randomString( 50 )
-
- localCache.get keys[ i ], ( err, success )->
+ localCache.get keys[ i ], ( err, res )->
n++
- assert.ok( success )
+ pred = {}
+ pred[ keys[ i ] ] = vals[ i ]
+ assert.eql( pred, res )
assert.isNull( err, err )
localCache.del keys[ i ], ( err, success )->
n++
- assert.ok( success )
assert.isNull( err, err )
+ assert.ok( success )
# generate `count` misses
for i in [1..count]
# 4 char key should not exist
localCache.get "xxxx", ( err, res )->
++n
- assert.isNull( res, res )
- assert.equal( 'not-found', err.errorcode )
+ assert.isNull( err, err )
+ assert.eql( {}, res )
end = localCache.getStats()
- console.log start, end
+
+ # check predicted stats
assert.equal( end.hits - start.hits, 5, "hits wrong" )
assert.equal( end.misses - start.misses, 5, "misses wrong" )
assert.equal( end.keys - start.keys, 5, "hits wrong" )
View
133 test/node_cache-test.js
@@ -1,7 +1,6 @@
(function() {
- var VCache, ks, localCache, randomString, vs;
- root._ = require("../node_modules/underscore");
- root.utils = require("../lib/utils");
+ var VCache, ks, localCache, randomString, vs, _;
+ _ = require("underscore");
VCache = require("../lib/node_cache");
localCache = new VCache({
stdTTL: '15m'
@@ -29,20 +28,60 @@
ks = [];
module.exports = {
"general": function(beforeExit, assert) {
- var done, key, value;
- done = false;
+ var key, n, start, value, value2;
+ n = 0;
+ start = _.clone(localCache.getStats());
value = randomString(100);
+ value2 = randomString(100);
key = randomString(10);
localCache.set(key, value, 0, function(err, res) {
assert.isNull(err, err);
- return localCache.get(key, function(err, res) {
- done = true;
- assert.equal(value, res);
- return console.log("general stats:", localCache.getStats());
+ n++;
+ assert.equal(1, localCache.getStats().keys - start.keys);
+ localCache.get(key, function(err, res) {
+ var pred;
+ n++;
+ pred = {};
+ pred[key] = value;
+ return assert.eql(pred, res);
+ });
+ localCache.get("xxx", function(err, res) {
+ n++;
+ assert.isNull(err, err);
+ return assert.eql({}, res);
+ });
+ localCache.del("xxx", function(err, res) {
+ n++;
+ assert.isNull(err, err);
+ return assert.ok(res);
+ });
+ localCache.set(key, value2, 0, function(err, res) {
+ n++;
+ assert.isNull(err, err);
+ assert.ok(res, err);
+ return localCache.get(key, function(err, res) {
+ var pred;
+ n++;
+ pred = {};
+ pred[key] = value2;
+ assert.eql(pred, res);
+ return assert.equal(1, localCache.getStats().keys - start.keys);
+ });
+ });
+ return localCache.del(key, function(err, res) {
+ n++;
+ assert.isNull(err, err);
+ assert.ok(res);
+ assert.equal(0, localCache.getStats().keys - start.keys);
+ return localCache.get(key, function(err, res) {
+ n++;
+ assert.isNull(err, err);
+ return assert.eql({}, res);
+ });
});
});
return beforeExit(function() {
- return assert.equal(true, done, "not exited");
+ return assert.equal(8, n, "not exited");
});
},
"many": function(beforeExit, assert) {
@@ -67,8 +106,11 @@
for (_j = 0, _len2 = ks.length; _j < _len2; _j++) {
key = ks[_j];
localCache.get(key, function(err, res) {
+ var pred;
n++;
- return assert.equal(val, res);
+ pred = {};
+ pred[key] = val;
+ return assert.eql(pred, res);
});
}
console.log("TIME-GET:", new Date().getTime() - time);
@@ -86,14 +128,21 @@
ri = Math.floor(Math.random() * vs.length);
localCache.del(ks[i], function(err, success) {
n++;
+ assert.isNull(err, err);
+ return assert.ok(success);
+ });
+ }
+ for (i = 1; 1 <= count ? i <= count : i >= count; 1 <= count ? i++ : i--) {
+ ri = Math.floor(Math.random() * vs.length);
+ localCache.del(ks[i], function(err, success) {
+ n++;
assert.ok(success);
return assert.isNull(err, err);
});
}
- console.log("DELETE STATS:", localCache.getStats());
- assert.equal(localCache.getStats().keys, startKeys - n);
+ assert.equal(localCache.getStats().keys, startKeys - count);
return beforeExit(function() {
- return assert.equal(n, count);
+ return assert.equal(n, count * 2);
});
},
"ttl": function(beforeExit, assert) {
@@ -106,82 +155,94 @@
assert.isNull(err, err);
assert.ok(res);
return localCache.get(key, function(err, res) {
+ var pred;
assert.isNull(err, err);
- return assert.equal(val, res);
+ pred = {};
+ pred[key] = val;
+ return assert.eql(pred, res);
});
});
localCache.set(key2, val, 800, function(err, res) {
assert.isNull(err, err);
assert.ok(res);
return localCache.get(key2, function(err, res) {
+ var pred;
assert.isNull(err, err);
- return assert.equal(val, res);
+ pred = {};
+ pred[key2] = val;
+ return assert.eql(pred, res);
});
});
setTimeout(function() {
++n;
return localCache.get(key, function(err, res) {
+ var pred;
assert.isNull(err, err);
- return assert.equal(val, res);
+ pred = {};
+ pred[key] = val;
+ return assert.eql(pred, res);
});
}, 400);
setTimeout(function() {
++n;
return localCache.get(key, function(err, res) {
- assert.isNull(res, res);
- return assert.equal('not-found', err.errorcode);
+ assert.isNull(err, err);
+ return assert.eql({}, res);
});
}, 600);
- setTimeout(function() {
+ return setTimeout(function() {
++n;
return localCache.get(key2, function(err, res) {
+ var pred;
assert.isNull(err, err);
- return assert.equal(val, res);
+ pred = {};
+ pred[key2] = val;
+ assert.eql(pred, res);
+ return assert.eql(pred, res);
});
}, 600);
- return setTimeout(function() {
- return console.log("TTL STATS:", localCache.getStats());
- }, 700);
},
"stats": function(beforeExit, assert) {
- var count, end, i, key, keys, n, start, val, _ref;
+ var count, end, i, key, keys, n, start, val, vals, _ref;
n = 0;
start = _.clone(localCache.getStats());
count = 5;
keys = [];
+ vals = [];
for (i = 1, _ref = count * 2; 1 <= _ref ? i <= _ref : i >= _ref; 1 <= _ref ? i++ : i--) {
key = randomString(7);
val = randomString(50);
keys.push(key);
+ vals.push(val);
localCache.set(key, val, 0, function(err, success) {
n++;
- assert.ok(success);
- return assert.isNull(err, err);
+ assert.isNull(err, err);
+ return assert.ok(success);
});
}
for (i = 1; 1 <= count ? i <= count : i >= count; 1 <= count ? i++ : i--) {
- key = randomString(7);
- val = randomString(50);
- localCache.get(keys[i], function(err, success) {
+ localCache.get(keys[i], function(err, res) {
+ var pred;
n++;
- assert.ok(success);
+ pred = {};
+ pred[keys[i]] = vals[i];
+ assert.eql(pred, res);
return assert.isNull(err, err);
});
localCache.del(keys[i], function(err, success) {
n++;
- assert.ok(success);
- return assert.isNull(err, err);
+ assert.isNull(err, err);
+ return assert.ok(success);
});
}
for (i = 1; 1 <= count ? i <= count : i >= count; 1 <= count ? i++ : i--) {
localCache.get("xxxx", function(err, res) {
++n;
- assert.isNull(res, res);
- return assert.equal('not-found', err.errorcode);
+ assert.isNull(err, err);
+ return assert.eql({}, res);
});
}
end = localCache.getStats();
- console.log(start, end);
assert.equal(end.hits - start.hits, 5, "hits wrong");
assert.equal(end.misses - start.misses, 5, "misses wrong");
assert.equal(end.keys - start.keys, 5, "hits wrong");
Please sign in to comment.
Something went wrong with that request. Please try again.