Skip to content

Commit

Permalink
Merge pull request #246 from tharropoulos/fix-cache
Browse files Browse the repository at this point in the history
Request cache: Fix type error when deleting possibly undefined oldest entry
  • Loading branch information
jasonbosco authored Nov 18, 2024
2 parents 8baab7a + 72386df commit 72f0c90
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 72f0c90

Please sign in to comment.