Skip to content

Commit

Permalink
Only run size-based eviction of maxSize is greater than 0; fixes #257
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaps125 authored and isaacs committed Nov 2, 2022
1 parent fd370b8 commit ff254a7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions index.js
Expand Up @@ -400,9 +400,11 @@ class LRUCache {
}
this.addItemSize = (index, size) => {
this.sizes[index] = size
const maxSize = this.maxSize - this.sizes[index]
while (this.calculatedSize > maxSize) {
this.evict(true)
if (this.maxSize) {
const maxSize = this.maxSize - this.sizes[index]
while (this.calculatedSize > maxSize) {
this.evict(true)
}
}
this.calculatedSize += this.sizes[index]
}
Expand Down

0 comments on commit ff254a7

Please sign in to comment.