Skip to content

Commit

Permalink
Merge 42f2f1b into 8d1362d
Browse files Browse the repository at this point in the history
  • Loading branch information
renjie1996 committed Sep 23, 2019
2 parents 8d1362d + 42f2f1b commit dc12533
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -108,7 +108,7 @@ class QuickLRU {
}
}

return this._size + oldCacheSize;
return Math.min(this._size + oldCacheSize, this.maxSize);
}
}

Expand Down
9 changes: 9 additions & 0 deletions test.js
Expand Up @@ -166,6 +166,15 @@ test('.size - accounts for duplicates', t => {
t.is(lru.size, 2);
});

test('max size', t => {
const lru = new QuickLRU({maxSize: 3});
lru.set('1', 1);
lru.set('2', 2);
lru.set('3', 3);
lru.set('4', 4);
t.is(lru.size, 3);
});

test('checks total cache size does not exceed `maxSize`', t => {
const lru = new QuickLRU({maxSize: 2});
lru.set('1', 1);
Expand Down

0 comments on commit dc12533

Please sign in to comment.