Unverified Commit cd65c520 authored by Sebastian Markbåge's avatar Sebastian Markbåge Committed by GitHub

Remove shouldRevalidateStale concept from CacheHandlers (#70493)

We want to immediately expire any stale entries from memory caches. So
we just have treat them as missing/expired directly.
parent 523f1daa
...@@ -24,13 +24,17 @@ import type { ManifestNode } from '../../build/webpack/plugins/flight-manifest-p ...@@ -24,13 +24,17 @@ import type { ManifestNode } from '../../build/webpack/plugins/flight-manifest-p
type CacheEntry = { type CacheEntry = {
value: ReadableStream value: ReadableStream
// In-memory caches are fragile and should not use stale-while-revalidate
// semantics on the caches because it's not worth warming up an entry that's
// likely going to get evicted before we get to use it anyway. However,
// we also don't want to reuse a stale entry for too long so stale entries
// should be considered expired/missing in such CacheHandlers.
stale: boolean stale: boolean
} }
interface CacheHandler { interface CacheHandler {
get(cacheKey: string | ArrayBuffer): Promise<undefined | CacheEntry> get(cacheKey: string | ArrayBuffer): Promise<undefined | CacheEntry>
set(cacheKey: string | ArrayBuffer, value: ReadableStream): Promise<void> set(cacheKey: string | ArrayBuffer, value: ReadableStream): Promise<void>
shouldRevalidateStale: boolean
} }
const cacheHandlerMap: Map<string, CacheHandler> = new Map() const cacheHandlerMap: Map<string, CacheHandler> = new Map()
...@@ -64,10 +68,6 @@ cacheHandlerMap.set('default', { ...@@ -64,10 +68,6 @@ cacheHandlerMap.set('default', {
await value.cancel() await value.cancel()
} }
}, },
// In-memory caches are fragile and should not use stale-while-revalidate
// semantics on the caches because it's not worth warming up an entry that's
// likely going to get evicted before we get to use it anyway.
shouldRevalidateStale: false,
}) })
// TODO: Consider moving this another module that is guaranteed to be required in a safe scope. // TODO: Consider moving this another module that is guaranteed to be required in a safe scope.
...@@ -198,7 +198,7 @@ export function cache(kind: string, id: string, fn: any) { ...@@ -198,7 +198,7 @@ export function cache(kind: string, id: string, fn: any) {
let stream let stream
if ( if (
entry === undefined || entry === undefined ||
(staticGenerationStore.isStaticGeneration && entry.stale) (entry.stale && staticGenerationStore.isStaticGeneration)
) { ) {
// Miss. Generate a new result. // Miss. Generate a new result.
...@@ -221,11 +221,9 @@ export function cache(kind: string, id: string, fn: any) { ...@@ -221,11 +221,9 @@ export function cache(kind: string, id: string, fn: any) {
) )
} else { } else {
stream = entry.value stream = entry.value
if (entry.stale && cacheHandler.shouldRevalidateStale) { if (entry.stale) {
// If this is stale, and we're not in a prerender (i.e. this is dynamic render), // If this is stale, and we're not in a prerender (i.e. this is dynamic render),
// then we should warm up the cache with a fresh revalidated entry. We only do this // then we should warm up the cache with a fresh revalidated entry.
// for long lived cache handlers because it's not worth warming up the cache with an
// an entry that's just going to get evicted before we can use it anyway.
const ignoredStream = await runInCleanSnapshot( const ignoredStream = await runInCleanSnapshot(
generateCacheEntry, generateCacheEntry,
staticGenerationStore, staticGenerationStore,
......
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