From 1cf442487044b4719ddce55d80ab39543872cf59 Mon Sep 17 00:00:00 2001 From: sveisvei Date: Thu, 29 Dec 2016 11:08:41 +0100 Subject: [PATCH] evict if new item directly is not eligible --- lib/client-metrics/ttl-list.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/client-metrics/ttl-list.js b/lib/client-metrics/ttl-list.js index 208277fcc9..8049645b50 100644 --- a/lib/client-metrics/ttl-list.js +++ b/lib/client-metrics/ttl-list.js @@ -37,11 +37,15 @@ module.exports = class TTLList extends EventEmitter { add (value, timestamp = new Date()) { const ttl = moment(timestamp).add(this.expireAmount, this.expireType); - this.list.add({ ttl, value }); + if (moment().isBefore(ttl)) { + this.list.add({ ttl, value }); + } else { + this.emit('expire', value, ttl); + } } timedCheck () { - const now = moment(new Date()); + const now = moment(); this.list.reverseRemoveUntilTrue(({ value }) => now.isBefore(value.ttl)); this.startTimer(); }