Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Naming refactor

  • Loading branch information...
commit b7ee5f9df6e87ded72994533f21ca31d86ee69bd 1 parent a432473
@serby authored
View
2  benchmark/engine.bench.js
@@ -1,5 +1,5 @@
var async = require('async')
- , count = 200000
+ , count = 100000
;
function time(fn) {
View
45 benchmark/hash-delete.js
@@ -0,0 +1,45 @@
+var hash = {}
+ , maxSize = 1000000
+ , steps = 100
+ ;
+
+function setup(size) {
+ hash = {};
+ for (var i = 0; i < size; i++) {
+ hash['key' + i] = i;
+ }
+}
+
+function del(count) {
+ for (var i = 0; i < count; i++) {
+ delete hash['key' + i];
+ }
+}
+
+function createTimer() {
+ var start;
+ return {
+ start: function() {
+ start = Date.now();
+ },
+ getTime: function() {
+ return Date.now() - start;
+ }
+ };
+}
+
+for( var i = 1; i <= steps; i += 1) {
+
+ var size = Math.round((maxSize / steps) * i)
+ , timer = createTimer()
+ ;
+
+ timer.start();
+ setup(size);
+ console.log('Created hash with ' + size + ' values in ' + timer.getTime() + 'ms');
+
+ timer.start();
+ del(size);
+ console.log('Deleted ' + size + ' values from hash in ' + timer.getTime() + 'ms');
+
+}
View
11 benchmark/memoryCacheEngine.bench.js
@@ -1,11 +0,0 @@
-var async = require('async')
- , _ = require('underscore');
-
-require('./engine.bench')('memoryCacheEngine', function(options) {
-
- options = _.extend({
- gcInterval: 30000
- }, options);
-
- return require('../lib/memoryCacheEngine').createMemoryCacheEngine(options);
-});
View
11 benchmark/memoryEngine.bench.js
@@ -0,0 +1,11 @@
+var async = require('async')
+ , _ = require('underscore');
+
+require('./engine.bench')('memoryEngine', function(options) {
+
+ options = _.extend({
+ gcInterval: 30000
+ }, options);
+
+ return require('../lib/memoryEngine')(options);
+});
View
20 lib/memoryCacheEngine.js → lib/memoryEngine.js
@@ -1,6 +1,6 @@
-module.exports.createMemoryCacheEngine = function(options) {
+module.exports = function(options) {
- var syncMemory = require('./syncMemoryCacheEngine').createSyncMemoryCacheEngine();
+ var synchronousMemory = require('./synchronousMemoryEngine')();
return {
set: function(key, value, ttl, callback) {
@@ -10,7 +10,7 @@ module.exports.createMemoryCacheEngine = function(options) {
ttl = undefined;
}
- syncMemory.set(key, value, ttl);
+ synchronousMemory.set(key, value, ttl);
if (typeof callback === 'function') {
callback(undefined, value);
@@ -18,25 +18,25 @@ module.exports.createMemoryCacheEngine = function(options) {
},
get: function(key, callback) {
- callback(undefined, syncMemory.get(key));
+ callback(undefined, synchronousMemory.get(key));
},
del: function(key, callback) {
- var value = syncMemory.del(key);
+ synchronousMemory.del(key);
if (typeof callback === 'function') {
- callback(undefined, value);
+ callback(undefined);
}
},
clear: function(callback) {
- callback(undefined, syncMemory.clear());
+ callback(undefined, synchronousMemory.clear());
},
size: function(callback) {
- callback(undefined, syncMemory.size());
+ callback(undefined, synchronousMemory.size());
},
dump: function(callback) {
- callback(undefined, syncMemory.dump());
+ callback(undefined, synchronousMemory.dump());
},
close: function(callback) {
- syncMemory.close();
+ synchronousMemory.close();
if (typeof callback === 'function') {
callback();
}
View
3  lib/syncMemoryCacheEngine.js → lib/synchronousMemoryEngine.js
@@ -1,6 +1,6 @@
var _ = require('underscore');
-module.exports.createSyncMemoryCacheEngine = function(options) {
+module.exports = function(options) {
var cache
, lru
@@ -24,7 +24,6 @@ module.exports.createSyncMemoryCacheEngine = function(options) {
delete lru[item.lru];
delete cache[key];
}
- return item.value;
}
function garbageCollection() {
View
2  lib/uber-cache.js
@@ -14,7 +14,7 @@ module.exports.createUberCache = function(options) {
hasher: hasher
}, options);
- options.engine = options.engine || require('./memoryCacheEngine').createMemoryCacheEngine(options);
+ options.engine = options.engine || require('./memoryEngine')(options);
function memoize(fn, ttl, callback) {
var fnKey = '_func' + funcCounter
View
11 test/memoryCacheEngine.test.js
@@ -1,11 +0,0 @@
-var async = require('async')
- , _ = require('underscore');
-
-require('./engine')('memoryCacheEngine', function(options) {
-
- options = _.extend({
- gcInterval: 100
- }, options);
-
- return require('../lib/memoryCacheEngine').createMemoryCacheEngine(options);
-});
View
10 test/memoryEngine.test.js
@@ -0,0 +1,10 @@
+var _ = require('underscore');
+
+require('./engine')('memoryEngine', function(options) {
+
+ options = _.extend({
+ gcInterval: 100
+ }, options);
+
+ return require('../lib/memoryEngine')(options);
+});
View
34 test/syncMemoryCacheEngine.test.js → test/synchronousEngine.test.js
@@ -1,40 +1,40 @@
var should = require('should')
- , createSyncMemoryCacheEngine = require('../lib/syncMemoryCacheEngine').createSyncMemoryCacheEngine
+ , createsynchronousMemoryEngine = require('../lib/synchronousMemoryEngine')
;
-describe('syncMemoryCacheEngine', function() {
+describe('synchronousMemoryEngine', function() {
describe('#get()', function() {
it('should return undefined for a key that has not been set', function() {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
should.equal(memory.get('test'), undefined);
});
it('should return value via callback if provided', function() {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
memory.set('test', 'hello');
memory.get('test', function(error, value) {
value.should.eql('hello');
});
});
it('should return value for a key that has been set', function() {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
memory.set('test', 'hello');
should.equal(memory.get('test'), 'hello');
});
it('should not return a value for a key that has been cleared', function() {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
memory.set('test', 'hello');
should.equal(memory.get('test'), 'hello');
memory.clear('test');
should.equal(memory.get('test'), undefined);
});
it('should return a value when within the TTL', function() {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
memory.set('test', 'hello', 2);
should.equal(memory.get('test'), 'hello');
});
it('should not return when TTL has been exceeded', function(done) {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
memory.set('test', 'hello', 1);
setTimeout(function() {
should.equal(memory.get('test'), undefined);
@@ -45,7 +45,7 @@ describe('syncMemoryCacheEngine', function() {
describe('#set()', function() {
it('should not allow undefined key', function() {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
(function() {
memory.set(undefined, '');
}).should.throw('Invalid key undefined');
@@ -54,11 +54,11 @@ describe('syncMemoryCacheEngine', function() {
describe('#del()', function() {
it('should not error if key does not exist', function() {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
memory.del('');
});
it('should reduce size of cache', function() {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
memory.set('a', 1);
memory.size().should.eql(1);
memory.del('a');
@@ -68,18 +68,18 @@ describe('syncMemoryCacheEngine', function() {
describe('#size', function() {
it('should return 0 before anything has been added to the cache', function() {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
memory.size().should.eql(0);
});
it('should return 1 after something has been added to the cache', function() {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
memory.set('test', 'hello');
memory.size().should.eql(1);
});
it('should return 0 after something added has expired', function(done) {
- var memory = createSyncMemoryCacheEngine();
+ var memory = createsynchronousMemoryEngine();
memory.set('test', 'hello', 1);
memory.size().should.eql(1);
setTimeout(function() {
@@ -90,7 +90,7 @@ describe('syncMemoryCacheEngine', function() {
it('should not exceed cache size', function() {
- var memory = createSyncMemoryCacheEngine({ size: 3 });
+ var memory = createsynchronousMemoryEngine({ size: 3 });
memory.set('a', 'a');
memory.size().should.eql(1);
@@ -108,7 +108,7 @@ describe('syncMemoryCacheEngine', function() {
it('should remove oldest from the cache first', function() {
- var memory = createSyncMemoryCacheEngine({ size: 3 });
+ var memory = createsynchronousMemoryEngine({ size: 3 });
memory.set('a', 'a');
memory.size().should.eql(1);
@@ -122,7 +122,7 @@ describe('syncMemoryCacheEngine', function() {
it('should not increase the length when overwriting a ', function() {
- var memory = createSyncMemoryCacheEngine({ size: 3 });
+ var memory = createsynchronousMemoryEngine({ size: 3 });
memory.set('a', 'a');
memory.size().should.eql(1);
Please sign in to comment.
Something went wrong with that request. Please try again.