Unverified Commit 61c99889 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update global cache handler ref (#71263)

This moves this out of the request context as it can be it's own global
symbol instead.
parent 982392e1
...@@ -23,7 +23,6 @@ import { ...@@ -23,7 +23,6 @@ import {
} from '../../../lib/constants' } from '../../../lib/constants'
import { toRoute } from '../to-route' import { toRoute } from '../to-route'
import { SharedRevalidateTimings } from './shared-revalidate-timings' import { SharedRevalidateTimings } from './shared-revalidate-timings'
import { getBuiltinRequestContext } from '../../after/builtin-request-context'
export interface CacheHandlerContext { export interface CacheHandlerContext {
fs?: CacheFs fs?: CacheFs
...@@ -44,6 +43,8 @@ export interface CacheHandlerValue { ...@@ -44,6 +43,8 @@ export interface CacheHandlerValue {
value: IncrementalCacheValue | null value: IncrementalCacheValue | null
} }
export const cacheHandlersSymbol = Symbol('@next/cache-handlers')
export class CacheHandler { export class CacheHandler {
// eslint-disable-next-line // eslint-disable-next-line
constructor(_ctx: CacheHandlerContext) {} constructor(_ctx: CacheHandlerContext) {}
...@@ -122,28 +123,35 @@ export class IncrementalCache implements IncrementalCacheType { ...@@ -122,28 +123,35 @@ export class IncrementalCache implements IncrementalCacheType {
const debug = !!process.env.NEXT_PRIVATE_DEBUG_CACHE const debug = !!process.env.NEXT_PRIVATE_DEBUG_CACHE
this.hasCustomCacheHandler = Boolean(CurCacheHandler) this.hasCustomCacheHandler = Boolean(CurCacheHandler)
const globalCacheHandler = getBuiltinRequestContext()?.NextCacheHandler const _globalThis: typeof globalThis & {
[cacheHandlersSymbol]?: {
if (globalCacheHandler) { FetchCache?: typeof CacheHandler
CurCacheHandler = globalCacheHandler }
} } = globalThis
if (!CurCacheHandler) { if (!CurCacheHandler) {
if (fs && serverDistDir) { // if we have a global cache handler available leverage it
if (debug) { const globalCacheHandler = _globalThis[cacheHandlersSymbol]
console.log('using filesystem cache handler')
if (globalCacheHandler?.FetchCache) {
CurCacheHandler = globalCacheHandler.FetchCache
} else {
if (fs && serverDistDir) {
if (debug) {
console.log('using filesystem cache handler')
}
CurCacheHandler = FileSystemCache
} }
CurCacheHandler = FileSystemCache if (
} FetchCache.isAvailable({ _requestHeaders: requestHeaders }) &&
if ( minimalMode &&
FetchCache.isAvailable({ _requestHeaders: requestHeaders }) && fetchCache
minimalMode && ) {
fetchCache if (debug) {
) { console.log('using fetch cache handler')
if (debug) { }
console.log('using fetch cache handler') CurCacheHandler = FetchCache
} }
CurCacheHandler = FetchCache
} }
} else if (debug) { } else if (debug) {
console.log('using custom cache handler', CurCacheHandler.name) console.log('using custom cache handler', CurCacheHandler.name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment