Skip to content

Commit f9d07a9

Browse files
committed
Make 'remainingTime' logic more clear in importJson()
1 parent e0882a3 commit f9d07a9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

index.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,21 @@ function Cache () {
164164

165165
var record = cacheToImport[key];
166166

167-
// This could possibly be `'NaN'` if there's no expiry set.
167+
// record.expire could be `'NaN'` if no expiry was set.
168+
// Try to subtract from it; a string minus a number is `NaN`, which is perfectly fine here.
168169
var remainingTime = record.expire - currTime;
169170

170171
if (remainingTime <= 0) {
171-
// Delete any record that might exist with the same key.
172+
// Delete any record that might exist with the same key, since this key is expired.
172173
this.del(key);
173174
continue;
174175
}
175176

176-
// Remaining time is either positive, or `'NaN'`.
177-
this.put(key, record.value, remainingTime > 0 ? remainingTime : undefined);
177+
// Remaining time must now be either positive or `NaN`,
178+
// but `put` will throw an error if we try to give it `NaN`.
179+
remainingTime = remainingTime > 0 ? remainingTime : undefined;
180+
181+
this.put(key, record.value, remainingTime);
178182
}
179183
}
180184

0 commit comments

Comments
 (0)