Skip to content

Commit

Permalink
chore: improve logic
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel committed Sep 20, 2024
1 parent dfedb43 commit 4b22884
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ export const createLRU = <Key, Value>(options: CacheOptions<Key, Value>) => {

valList[index] = value;

const keyMaxAge =
options?.staleAt !== undefined ? options.staleAt : staleAt;
const keyMaxAge = options?.staleAt ?? staleAt;

if (keyMaxAge !== undefined) {
if (typeof keyMaxAge !== 'number' || keyMaxAge <= 0)
Expand Down Expand Up @@ -364,12 +363,9 @@ export const createLRU = <Key, Value>(options: CacheOptions<Key, Value>) => {
keyMap.clear();
keyList.fill(undefined);
valList.fill(undefined);

if (staleAt !== undefined) {
expList.fill(0);
ageList.fill(0);
staleList.fill(0);
}
expList.fill(0);
ageList.fill(0);
staleList.fill(0);

free = [];
size = 0;
Expand Down

0 comments on commit 4b22884

Please sign in to comment.