Skip to content

Commit

Permalink
Fix cache size becoming double of the defined size (sindresorhus#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapatadia authored and sindresorhus committed May 29, 2019
1 parent 226a2d2 commit d6c7e11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class QuickLRU {

if (this.oldCache.has(key)) {
const value = this.oldCache.get(key);
this.oldCache.delete(key);
this._set(key, value);
return value;
}
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,11 @@ test('.size - accounts for dupes', t => {
const lru = lruWithDuplicates();
t.is(lru.size, 2);
});

test('checks total cache size does not exceed maxSize', t => {
const lru = new QuickLRU({maxSize: 2});
lru.set('1', 1);
lru.set('2', 2);
lru.get('1');
t.is(lru.oldCache.has('1'), false);
});

0 comments on commit d6c7e11

Please sign in to comment.