Permalink
Browse files

Add support for callback event on key expiration

  • Loading branch information...
1 parent 31c7ce0 commit 4d5d7cd2fc3be6cd62b8a069271a9106ae149f67 @loris loris committed Jan 21, 2013
Showing with 4 additions and 1 deletion.
  1. +4 −1 index.js
View
@@ -4,7 +4,7 @@ var debug = false;
var hitCount = 0;
var missCount = 0;
-exports.put = function(key, value, time) {
+exports.put = function(key, value, time, timeoutCallback) {
if (debug) console.log('caching: '+key+' = '+value+' (@'+time+')');
var oldRecord = cache[key];
if (oldRecord) {
@@ -17,6 +17,9 @@ exports.put = function(key, value, time) {
if (!isNaN(expire)) {
var timeout = setTimeout(function() {
exports.del(key);
+ if (typeof timeoutCallback === 'function') {
+ timeoutCallback(key);
+ }
}, time);
record.timeout = timeout;
}

0 comments on commit 4d5d7cd

Please sign in to comment.