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";
77
88export const STATUS_DELETED = 1 ;
99
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+
1027/**
1128 * Open Next cache based on cloudflare KV and Assets.
1229 *
@@ -62,6 +79,17 @@ class Cache implements IncrementalCache {
6279 } ;
6380 }
6481 }
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+
6593 this . debug ( entry ? `-> hit` : `-> miss` ) ;
6694 return { value : entry ?. value , lastModified : entry ?. lastModified } ;
6795 } catch {
You can’t perform that action at this time.
0 commit comments