File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
packages/cloudflare/src/api Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @opennextjs/cloudflare " : patch
3
+ ---
4
+
5
+ Fix: make sure ` kvCache ` discards expired entries
Original file line number Diff line number Diff line change @@ -7,6 +7,23 @@ export const CACHE_ASSET_DIR = "cnd-cgi/_next_cache";
7
7
8
8
export const STATUS_DELETED = 1 ;
9
9
10
+ // https://github.com/vercel/next.js/blob/9a1cd356/packages/next/src/server/response-cache/types.ts#L26-L38
11
+ export type CachedFetchValue = {
12
+ kind : "FETCH" ;
13
+ data : {
14
+ headers : { [ k : string ] : string } ;
15
+ body : string ;
16
+ url : string ;
17
+ status ?: number ;
18
+ // field used by older versions of Next.js (see: https://github.com/vercel/next.js/blob/fda1ecc/packages/next/src/server/response-cache/types.ts#L23)
19
+ tags ?: string [ ] ;
20
+ } ;
21
+ // tags are only present with file-system-cache
22
+ // fetch cache stores tags outside of cache entry
23
+ tags ?: string [ ] ;
24
+ revalidate : number ;
25
+ } ;
26
+
10
27
/**
11
28
* Open Next cache based on cloudflare KV and Assets.
12
29
*
@@ -62,6 +79,17 @@ class Cache implements IncrementalCache {
62
79
} ;
63
80
}
64
81
}
82
+
83
+ const entryValue = entry ?. value as CachedFetchValue | undefined ;
84
+ if ( entryValue ?. kind === "FETCH" ) {
85
+ const expires = entryValue . data . headers ?. expires ;
86
+ const expiresTime = new Date ( expires as string ) . getTime ( ) ;
87
+ if ( ! isNaN ( expiresTime ) && expiresTime <= Date . now ( ) ) {
88
+ this . debug ( `found expired entry (expire time: ${ expires } )` ) ;
89
+ return { } ;
90
+ }
91
+ }
92
+
65
93
this . debug ( entry ? `-> hit` : `-> miss` ) ;
66
94
return { value : entry ?. value , lastModified : entry ?. lastModified } ;
67
95
} catch {
You can’t perform that action at this time.
0 commit comments