Skip to content

Commit

Permalink
fix(req-cache): ensure oldest entry is defined before deleting it
Browse files Browse the repository at this point in the history
  • Loading branch information
tharropoulos committed Nov 18, 2024
1 parent 8d18aa6 commit 72386df
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Typesense/RequestWithCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ export default class RequestWithCache {
const isCacheOverMaxSize = this.responseCache.size > maxSize;
if (isCacheOverMaxSize) {
const oldestEntry = this.responseCache.keys().next().value;
this.responseCache.delete(oldestEntry);
if (oldestEntry) {
this.responseCache.delete(oldestEntry);
}
}
const isResponsePromiseCacheOverMaxSize =
this.responsePromiseCache.size > maxSize;
if (isResponsePromiseCacheOverMaxSize) {
const oldestEntry = this.responsePromiseCache.keys().next().value;
this.responsePromiseCache.delete(oldestEntry);
if (oldestEntry) {
this.responsePromiseCache.delete(oldestEntry);
}
}
return response as T;
}
Expand Down

0 comments on commit 72386df

Please sign in to comment.