看了下源码,通过设置var interval = setInterval(this.resetAll, windowMs)来进行每隔windowMs豪秒清空统计次数。 但随后又调用了interval.unref()来暂停该定时器。请问为什么要暂停该时时器呢?
function MemoryStore(windowMs) {
var hits = {};
this.incr = function(key, cb) {
if (hits[key]) {
hits[key]++;
} else {
hits[key] = 1;
}
cb(null, hits[key]);
};
this.resetAll = function() {
hits = {};
};
// export an API to allow hits from one or all IPs to be reset
this.resetKey = function(key) {
delete hits[key];
};
// simply reset ALL hits every windowMs
var interval = setInterval(this.resetAll, windowMs);
if (interval.unref) {
interval.unref();
}
}
module.exports = MemoryStore;