Skip to content

Commit fc72eb5

Browse files
discard expired entries in the kvCache get
1 parent 642c3d2 commit fc72eb5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/cloudflare/src/api/kvCache.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ class Cache implements IncrementalCache {
6262
};
6363
}
6464
}
65+
66+
const entryValue = entry?.value as Record<string, unknown>;
67+
if (entryValue.kind === "FETCH") {
68+
const data = (entryValue.data as Record<string, string> | undefined)?.headers as
69+
| Record<string, string>
70+
| undefined;
71+
const expires = data?.expires;
72+
const expiresTime = new Date(expires as string).getTime();
73+
if (!isNaN(expiresTime) && expiresTime <= new Date().getTime()) {
74+
this.debug(entry ? `-> hit` : `-> miss`);
75+
// the entry is expired, so let's ignore it
76+
entry = null;
77+
}
78+
}
79+
6580
this.debug(entry ? `-> hit` : `-> miss`);
6681
return { value: entry?.value, lastModified: entry?.lastModified };
6782
} catch {

0 commit comments

Comments
 (0)