Skip to content

Commit

Permalink
fix: LRU cache memory leak. (#475)
Browse files Browse the repository at this point in the history
Fixes #474
  • Loading branch information
kinyoklion authored May 31, 2024
1 parent 8ff641b commit a5fdefc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/shared/sdk-server/__tests__/cache/LruCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ it('when it has been cleared', () => {
expect(lruCache.get(i.toString())).toBeUndefined();
}

// Fill the cache with integers again.
// Fill the cache with integers in a different range.
for (let i = 0; i < max; i += 1) {
lruCache.set(`${i}`, i);
lruCache.set(`${i + 100}`, i);
}

// Check they are all there.
for (let i = 0; i < max; i += 1) {
expect(lruCache.get(i.toString())).toEqual(i);
expect(lruCache.get(`${i + 100}`)).toEqual(i);
}

// Check old keys don't associate with new values.
for (let i = 0; i < max; i += 1) {
expect(lruCache.get(i.toString())).toBeUndefined();
}
});

Expand Down
1 change: 1 addition & 0 deletions packages/shared/sdk-server/src/cache/LruCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export default class LruCache {
this.keys.fill(undefined);
this.next.fill(0);
this.prev.fill(0);
this.keyMap.clear();
}

private index() {
Expand Down

0 comments on commit a5fdefc

Please sign in to comment.