Skip to content

Commit fffd2ec

Browse files
avoid unnecessary type casting in kvCache
1 parent 491dc53 commit fffd2ec

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

packages/cloudflare/src/api/kvCache.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import type {
2-
CachedFetchValue,
3-
CacheValue,
4-
IncrementalCache,
5-
WithLastModified,
6-
} from "@opennextjs/aws/types/overrides";
1+
import type { CacheValue, IncrementalCache, WithLastModified } from "@opennextjs/aws/types/overrides";
72
import { IgnorableError, RecoverableError } from "@opennextjs/aws/utils/error.js";
83

94
import { getCloudflareContext } from "./cloudflare-context.js";
@@ -70,12 +65,15 @@ class Cache implements IncrementalCache {
7065
// The cache can not be updated when there is no KV
7166
// As we don't want to keep serving stale data for ever,
7267
// we pretend the entry is not in cache
73-
const entryValue = entry?.value as CachedFetchValue;
74-
if (entryValue?.kind === "FETCH") {
75-
const expires = entryValue.data.headers?.expires;
76-
const expiresTime = new Date(expires as string).getTime();
68+
if (
69+
entry?.value &&
70+
"kind" in entry.value &&
71+
entry.value.kind === "FETCH" &&
72+
entry.value.data?.headers?.expires
73+
) {
74+
const expiresTime = new Date(entry.value.data.headers.expires).getTime();
7775
if (!isNaN(expiresTime) && expiresTime <= Date.now()) {
78-
this.debug(`found expired entry (expire time: ${expires})`);
76+
this.debug(`found expired entry (expire time: ${entry.value.data.headers.expires})`);
7977
return null;
8078
}
8179
}

0 commit comments

Comments
 (0)