@@ -23,7 +23,6 @@ import {
23
23
} from '../../../lib/constants'
24
24
import { toRoute } from '../to-route'
25
25
import { SharedRevalidateTimings } from './shared-revalidate-timings'
26
- import { getBuiltinRequestContext } from '../../after/builtin-request-context'
27
26
28
27
export interface CacheHandlerContext {
29
28
fs ?: CacheFs
@@ -44,6 +43,8 @@ export interface CacheHandlerValue {
44
43
value : IncrementalCacheValue | null
45
44
}
46
45
46
+ export const cacheHandlersSymbol = Symbol ( '@next/cache-handlers' )
47
+
47
48
export class CacheHandler {
48
49
// eslint-disable-next-line
49
50
constructor ( _ctx : CacheHandlerContext ) { }
@@ -122,28 +123,35 @@ export class IncrementalCache implements IncrementalCacheType {
122
123
const debug = ! ! process . env . NEXT_PRIVATE_DEBUG_CACHE
123
124
this . hasCustomCacheHandler = Boolean ( CurCacheHandler )
124
125
125
- const globalCacheHandler = getBuiltinRequestContext ( ) ?. NextCacheHandler
126
-
127
- if ( globalCacheHandler ) {
128
- CurCacheHandler = globalCacheHandler
129
- }
126
+ const _globalThis : typeof globalThis & {
127
+ [ cacheHandlersSymbol ] ?: {
128
+ FetchCache ?: typeof CacheHandler
129
+ }
130
+ } = globalThis
130
131
131
132
if ( ! CurCacheHandler ) {
132
- if ( fs && serverDistDir ) {
133
- if ( debug ) {
134
- console . log ( 'using filesystem cache handler' )
133
+ // if we have a global cache handler available leverage it
134
+ const globalCacheHandler = _globalThis [ cacheHandlersSymbol ]
135
+
136
+ if ( globalCacheHandler ?. FetchCache ) {
137
+ CurCacheHandler = globalCacheHandler . FetchCache
138
+ } else {
139
+ if ( fs && serverDistDir ) {
140
+ if ( debug ) {
141
+ console . log ( 'using filesystem cache handler' )
142
+ }
143
+ CurCacheHandler = FileSystemCache
135
144
}
136
- CurCacheHandler = FileSystemCache
137
- }
138
- if (
139
- FetchCache . isAvailable ( { _requestHeaders : requestHeaders } ) &&
140
- minimalMode &&
141
- fetchCache
142
- ) {
143
- if ( debug ) {
144
- console . log ( 'using fetch cache handler' )
145
+ if (
146
+ FetchCache . isAvailable ( { _requestHeaders : requestHeaders } ) &&
147
+ minimalMode &&
148
+ fetchCache
149
+ ) {
150
+ if ( debug ) {
151
+ console . log ( 'using fetch cache handler' )
152
+ }
153
+ CurCacheHandler = FetchCache
145
154
}
146
- CurCacheHandler = FetchCache
147
155
}
148
156
} else if ( debug ) {
149
157
console . log ( 'using custom cache handler' , CurCacheHandler . name )
0 commit comments