Permalink
Browse files

Merge pull request #10 from loris/patch-1

Add support for callback event on key expiration
  • Loading branch information...
ptarjan committed Feb 5, 2013
2 parents 31c7ce0 + 4d5d7cd commit 18cc1e55506327c9f82cc86895dbcc2c6de7b1d5
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 18cc1e5

Please sign in to comment.