1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

evict if new item directly is not eligible

This commit is contained in:
sveisvei 2016-12-29 11:08:41 +01:00 committed by Ivar Conradi Østhus
parent efc9ae2f5d
commit ae195b5674

View File

@ -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();
}