Skip to content

Commit

Permalink
add test for dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
qzaidi committed Jun 20, 2014
1 parent 5b9d316 commit a701700
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -166,7 +166,7 @@ var cache = {
}

};
log('created new cache function with name ' + fname);
log('created new cache function with name ' + fname + JSON.stringify(options));
cachedfunc.cacheName = fname;
return cachedfunc;
};
Expand Down
29 changes: 29 additions & 0 deletions test/maxkeys.js
@@ -0,0 +1,29 @@
"use strict";

var obcache = require('../index');
var debug = require('../debug');
var cache = debug.register(new obcache.Create({ max: 20,
dispose: console.log.bind('deposed '),
queueEnabled: true,
reset: { interval: 2000, firstReset: new Date(Date.now() + 1000) }
}));

(function() {
var original = function (id,cb) {
console.log('original called for ' + id);
process.nextTick(function() {
var v = JSON.stringify({ p: id });
cb(null,v);
});
};
var wrapped = cache.wrap(original);

for (var i=0; i < 40; i++) {
wrapped(i,console.log);
}

process.nextTick(function() {
debug.log();
});

}());

0 comments on commit a701700

Please sign in to comment.