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

Propagate expire/stale times the same way we do with revalidate (#71228)

This doesn't yet use them. That'll be a follow up.

Another follow up is to handle propagation of timestamps.
parent e814d045
...@@ -1784,6 +1784,8 @@ type PrerenderToStreamResult = { ...@@ -1784,6 +1784,8 @@ type PrerenderToStreamResult = {
ssrErrors: Array<unknown> ssrErrors: Array<unknown>
dynamicTracking?: null | DynamicTrackingState dynamicTracking?: null | DynamicTrackingState
collectedRevalidate: number collectedRevalidate: number
collectedExpire: number
collectedStale: number
collectedTags: null | string[] collectedTags: null | string[]
} }
...@@ -1945,6 +1947,8 @@ async function prerenderToStream( ...@@ -1945,6 +1947,8 @@ async function prerenderToStream(
// will track it again there // will track it again there
dynamicTracking: null, dynamicTracking: null,
revalidate: INFINITE_CACHE, revalidate: INFINITE_CACHE,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...ctx.requestStore.implicitTags], tags: [...ctx.requestStore.implicitTags],
}) })
...@@ -2036,6 +2040,8 @@ async function prerenderToStream( ...@@ -2036,6 +2040,8 @@ async function prerenderToStream(
controller: flightController, controller: flightController,
dynamicTracking, dynamicTracking,
revalidate: INFINITE_CACHE, revalidate: INFINITE_CACHE,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...ctx.requestStore.implicitTags], tags: [...ctx.requestStore.implicitTags],
}) })
...@@ -2098,6 +2104,8 @@ async function prerenderToStream( ...@@ -2098,6 +2104,8 @@ async function prerenderToStream(
// dynamic during SSR // dynamic during SSR
dynamicTracking, dynamicTracking,
revalidate: INFINITE_CACHE, revalidate: INFINITE_CACHE,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...ctx.requestStore.implicitTags], tags: [...ctx.requestStore.implicitTags],
} }
let SSRIsDynamic = false let SSRIsDynamic = false
...@@ -2202,6 +2210,8 @@ async function prerenderToStream( ...@@ -2202,6 +2210,8 @@ async function prerenderToStream(
dynamicTracking, dynamicTracking,
// TODO: Should this include the SSR pass? // TODO: Should this include the SSR pass?
collectedRevalidate: finalRenderPrerenderStore.revalidate, collectedRevalidate: finalRenderPrerenderStore.revalidate,
collectedExpire: finalRenderPrerenderStore.expire,
collectedStale: finalRenderPrerenderStore.stale,
collectedTags: finalRenderPrerenderStore.tags, collectedTags: finalRenderPrerenderStore.tags,
} }
} else { } else {
...@@ -2257,6 +2267,8 @@ async function prerenderToStream( ...@@ -2257,6 +2267,8 @@ async function prerenderToStream(
dynamicTracking, dynamicTracking,
// TODO: Should this include the SSR pass? // TODO: Should this include the SSR pass?
collectedRevalidate: finalRenderPrerenderStore.revalidate, collectedRevalidate: finalRenderPrerenderStore.revalidate,
collectedExpire: finalRenderPrerenderStore.expire,
collectedStale: finalRenderPrerenderStore.stale,
collectedTags: finalRenderPrerenderStore.tags, collectedTags: finalRenderPrerenderStore.tags,
} }
} }
...@@ -2312,6 +2324,8 @@ async function prerenderToStream( ...@@ -2312,6 +2324,8 @@ async function prerenderToStream(
controller: flightController, controller: flightController,
dynamicTracking, dynamicTracking,
revalidate: INFINITE_CACHE, revalidate: INFINITE_CACHE,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...ctx.requestStore.implicitTags], tags: [...ctx.requestStore.implicitTags],
}) })
...@@ -2393,6 +2407,8 @@ async function prerenderToStream( ...@@ -2393,6 +2407,8 @@ async function prerenderToStream(
controller: flightController, controller: flightController,
dynamicTracking, dynamicTracking,
revalidate: INFINITE_CACHE, revalidate: INFINITE_CACHE,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...ctx.requestStore.implicitTags], tags: [...ctx.requestStore.implicitTags],
}) })
...@@ -2411,6 +2427,8 @@ async function prerenderToStream( ...@@ -2411,6 +2427,8 @@ async function prerenderToStream(
// dynamic during SSR // dynamic during SSR
dynamicTracking, dynamicTracking,
revalidate: INFINITE_CACHE, revalidate: INFINITE_CACHE,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...ctx.requestStore.implicitTags], tags: [...ctx.requestStore.implicitTags],
} }
...@@ -2577,6 +2595,8 @@ async function prerenderToStream( ...@@ -2577,6 +2595,8 @@ async function prerenderToStream(
dynamicTracking, dynamicTracking,
// TODO: Should this include the SSR pass? // TODO: Should this include the SSR pass?
collectedRevalidate: finalRenderPrerenderStore.revalidate, collectedRevalidate: finalRenderPrerenderStore.revalidate,
collectedExpire: finalRenderPrerenderStore.expire,
collectedStale: finalRenderPrerenderStore.stale,
collectedTags: finalRenderPrerenderStore.tags, collectedTags: finalRenderPrerenderStore.tags,
} }
} }
...@@ -2591,6 +2611,8 @@ async function prerenderToStream( ...@@ -2591,6 +2611,8 @@ async function prerenderToStream(
implicitTags: ctx.requestStore.implicitTags, implicitTags: ctx.requestStore.implicitTags,
dynamicTracking, dynamicTracking,
revalidate: INFINITE_CACHE, revalidate: INFINITE_CACHE,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...ctx.requestStore.implicitTags], tags: [...ctx.requestStore.implicitTags],
}) })
const RSCPayload = await workUnitAsyncStorage.run( const RSCPayload = await workUnitAsyncStorage.run(
...@@ -2620,6 +2642,8 @@ async function prerenderToStream( ...@@ -2620,6 +2642,8 @@ async function prerenderToStream(
implicitTags: ctx.requestStore.implicitTags, implicitTags: ctx.requestStore.implicitTags,
dynamicTracking, dynamicTracking,
revalidate: INFINITE_CACHE, revalidate: INFINITE_CACHE,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...ctx.requestStore.implicitTags], tags: [...ctx.requestStore.implicitTags],
} }
const prerender = require('react-dom/static.edge') const prerender = require('react-dom/static.edge')
...@@ -2706,6 +2730,8 @@ async function prerenderToStream( ...@@ -2706,6 +2730,8 @@ async function prerenderToStream(
dynamicTracking, dynamicTracking,
// TODO: Should this include the SSR pass? // TODO: Should this include the SSR pass?
collectedRevalidate: reactServerPrerenderStore.revalidate, collectedRevalidate: reactServerPrerenderStore.revalidate,
collectedExpire: reactServerPrerenderStore.expire,
collectedStale: reactServerPrerenderStore.stale,
collectedTags: reactServerPrerenderStore.tags, collectedTags: reactServerPrerenderStore.tags,
} }
} else if (fallbackRouteParams && fallbackRouteParams.size > 0) { } else if (fallbackRouteParams && fallbackRouteParams.size > 0) {
...@@ -2721,6 +2747,8 @@ async function prerenderToStream( ...@@ -2721,6 +2747,8 @@ async function prerenderToStream(
dynamicTracking, dynamicTracking,
// TODO: Should this include the SSR pass? // TODO: Should this include the SSR pass?
collectedRevalidate: reactServerPrerenderStore.revalidate, collectedRevalidate: reactServerPrerenderStore.revalidate,
collectedExpire: reactServerPrerenderStore.expire,
collectedStale: reactServerPrerenderStore.stale,
collectedTags: reactServerPrerenderStore.tags, collectedTags: reactServerPrerenderStore.tags,
} }
} else { } else {
...@@ -2777,6 +2805,8 @@ async function prerenderToStream( ...@@ -2777,6 +2805,8 @@ async function prerenderToStream(
dynamicTracking, dynamicTracking,
// TODO: Should this include the SSR pass? // TODO: Should this include the SSR pass?
collectedRevalidate: reactServerPrerenderStore.revalidate, collectedRevalidate: reactServerPrerenderStore.revalidate,
collectedExpire: reactServerPrerenderStore.expire,
collectedStale: reactServerPrerenderStore.stale,
collectedTags: reactServerPrerenderStore.tags, collectedTags: reactServerPrerenderStore.tags,
} }
} }
...@@ -2786,6 +2816,8 @@ async function prerenderToStream( ...@@ -2786,6 +2816,8 @@ async function prerenderToStream(
phase: 'render', phase: 'render',
implicitTags: ctx.requestStore.implicitTags, implicitTags: ctx.requestStore.implicitTags,
revalidate: INFINITE_CACHE, revalidate: INFINITE_CACHE,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...ctx.requestStore.implicitTags], tags: [...ctx.requestStore.implicitTags],
}) })
// This is a regular static generation. We don't do dynamic tracking because we rely on // This is a regular static generation. We don't do dynamic tracking because we rely on
...@@ -2860,6 +2892,8 @@ async function prerenderToStream( ...@@ -2860,6 +2892,8 @@ async function prerenderToStream(
}), }),
// TODO: Should this include the SSR pass? // TODO: Should this include the SSR pass?
collectedRevalidate: prerenderLegacyStore.revalidate, collectedRevalidate: prerenderLegacyStore.revalidate,
collectedExpire: prerenderLegacyStore.expire,
collectedStale: prerenderLegacyStore.stale,
collectedTags: prerenderLegacyStore.tags, collectedTags: prerenderLegacyStore.tags,
} }
} }
...@@ -2943,6 +2977,8 @@ async function prerenderToStream( ...@@ -2943,6 +2977,8 @@ async function prerenderToStream(
phase: 'render', phase: 'render',
implicitTags: ctx.requestStore.implicitTags, implicitTags: ctx.requestStore.implicitTags,
revalidate: INFINITE_CACHE, revalidate: INFINITE_CACHE,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...ctx.requestStore.implicitTags], tags: [...ctx.requestStore.implicitTags],
}) })
const errorRSCPayload = await workUnitAsyncStorage.run( const errorRSCPayload = await workUnitAsyncStorage.run(
...@@ -3017,6 +3053,10 @@ async function prerenderToStream( ...@@ -3017,6 +3053,10 @@ async function prerenderToStream(
dynamicTracking: null, dynamicTracking: null,
collectedRevalidate: collectedRevalidate:
prerenderStore !== null ? prerenderStore.revalidate : INFINITE_CACHE, prerenderStore !== null ? prerenderStore.revalidate : INFINITE_CACHE,
collectedExpire:
prerenderStore !== null ? prerenderStore.expire : INFINITE_CACHE,
collectedStale:
prerenderStore !== null ? prerenderStore.stale : INFINITE_CACHE,
collectedTags: prerenderStore !== null ? prerenderStore.tags : null, collectedTags: prerenderStore !== null ? prerenderStore.tags : null,
} }
} catch (finalErr: any) { } catch (finalErr: any) {
......
...@@ -90,6 +90,8 @@ export type PrerenderStoreModern = { ...@@ -90,6 +90,8 @@ export type PrerenderStoreModern = {
// Collected revalidate times and tags for this document during the prerender. // Collected revalidate times and tags for this document during the prerender.
revalidate: number // in seconds. 0 means dynamic. INFINITE_CACHE and higher means never revalidate. revalidate: number // in seconds. 0 means dynamic. INFINITE_CACHE and higher means never revalidate.
expire: number // server expiration time
stale: number // client expiration time
tags: null | string[] tags: null | string[]
} & PhasePartial } & PhasePartial
...@@ -99,6 +101,8 @@ export type PrerenderStorePPR = { ...@@ -99,6 +101,8 @@ export type PrerenderStorePPR = {
readonly dynamicTracking: null | DynamicTrackingState readonly dynamicTracking: null | DynamicTrackingState
// Collected revalidate times and tags for this document during the prerender. // Collected revalidate times and tags for this document during the prerender.
revalidate: number // in seconds. 0 means dynamic. INFINITE_CACHE and higher means never revalidate. revalidate: number // in seconds. 0 means dynamic. INFINITE_CACHE and higher means never revalidate.
expire: number // server expiration time
stale: number // client expiration time
tags: null | string[] tags: null | string[]
} & PhasePartial } & PhasePartial
...@@ -107,6 +111,8 @@ export type PrerenderStoreLegacy = { ...@@ -107,6 +111,8 @@ export type PrerenderStoreLegacy = {
readonly implicitTags: string[] readonly implicitTags: string[]
// Collected revalidate times and tags for this document during the prerender. // Collected revalidate times and tags for this document during the prerender.
revalidate: number // in seconds. 0 means dynamic. INFINITE_CACHE and higher means never revalidate. revalidate: number // in seconds. 0 means dynamic. INFINITE_CACHE and higher means never revalidate.
expire: number // server expiration time
stale: number // client expiration time
tags: null | string[] tags: null | string[]
} & PhasePartial } & PhasePartial
...@@ -120,7 +126,11 @@ export type UseCacheStore = { ...@@ -120,7 +126,11 @@ export type UseCacheStore = {
readonly implicitTags: string[] readonly implicitTags: string[]
// Collected revalidate times and tags for this cache entry during the cache render. // Collected revalidate times and tags for this cache entry during the cache render.
revalidate: number // implicit revalidate time from inner caches / fetches revalidate: number // implicit revalidate time from inner caches / fetches
expire: number // server expiration time
stale: number // client expiration time
explicitRevalidate: undefined | number // explicit revalidate time from cacheLife() calls explicitRevalidate: undefined | number // explicit revalidate time from cacheLife() calls
explicitExpire: undefined | number // server expiration time
explicitStale: undefined | number // client expiration time
tags: null | string[] tags: null | string[]
} & PhasePartial } & PhasePartial
......
...@@ -352,6 +352,8 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -352,6 +352,8 @@ export class AppRouteRouteModule extends RouteModule<
controller: null, controller: null,
dynamicTracking, dynamicTracking,
revalidate: defaultRevalidate, revalidate: defaultRevalidate,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...implicitTags], tags: [...implicitTags],
}) })
...@@ -423,6 +425,8 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -423,6 +425,8 @@ export class AppRouteRouteModule extends RouteModule<
controller: finalController, controller: finalController,
dynamicTracking, dynamicTracking,
revalidate: defaultRevalidate, revalidate: defaultRevalidate,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...implicitTags], tags: [...implicitTags],
}) })
...@@ -495,6 +499,8 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -495,6 +499,8 @@ export class AppRouteRouteModule extends RouteModule<
phase: 'action', phase: 'action',
implicitTags: implicitTags, implicitTags: implicitTags,
revalidate: defaultRevalidate, revalidate: defaultRevalidate,
expire: INFINITE_CACHE,
stale: INFINITE_CACHE,
tags: [...implicitTags], tags: [...implicitTags],
} }
...@@ -570,6 +576,8 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -570,6 +576,8 @@ export class AppRouteRouteModule extends RouteModule<
prerenderStore.tags?.join(',') prerenderStore.tags?.join(',')
;(context.renderOpts as any).collectedRevalidate = ;(context.renderOpts as any).collectedRevalidate =
prerenderStore.revalidate prerenderStore.revalidate
;(context.renderOpts as any).collectedExpire = prerenderStore.expire
;(context.renderOpts as any).collectedStale = prerenderStore.stale
} }
// It's possible cookies were set in the handler, so we need // It's possible cookies were set in the handler, so we need
......
...@@ -140,4 +140,22 @@ export function cacheLife(profile: CacheLifeProfiles | CacheLife): void { ...@@ -140,4 +140,22 @@ export function cacheLife(profile: CacheLifeProfiles | CacheLife): void {
workUnitStore.explicitRevalidate = profile.revalidate workUnitStore.explicitRevalidate = profile.revalidate
} }
} }
if (profile.expire !== undefined) {
// Track the explicit expire time.
if (
workUnitStore.explicitExpire === undefined ||
workUnitStore.explicitExpire > profile.expire
) {
workUnitStore.explicitExpire = profile.expire
}
}
if (profile.stale !== undefined) {
// Track the explicit stale time.
if (
workUnitStore.explicitStale === undefined ||
workUnitStore.explicitStale > profile.stale
) {
workUnitStore.explicitStale = profile.stale
}
}
} }
...@@ -182,7 +182,11 @@ function generateCacheEntryWithCacheContext( ...@@ -182,7 +182,11 @@ function generateCacheEntryWithCacheContext(
? [] ? []
: outerWorkUnitStore.implicitTags, : outerWorkUnitStore.implicitTags,
revalidate: defaultCacheLife.revalidate, revalidate: defaultCacheLife.revalidate,
expire: defaultCacheLife.expire,
stale: defaultCacheLife.stale,
explicitRevalidate: undefined, explicitRevalidate: undefined,
explicitExpire: undefined,
explicitStale: undefined,
tags: null, tags: null,
} }
return workUnitAsyncStorage.run( return workUnitAsyncStorage.run(
...@@ -273,13 +277,21 @@ async function collectResult( ...@@ -273,13 +277,21 @@ async function collectResult(
innerCacheStore.explicitRevalidate !== undefined innerCacheStore.explicitRevalidate !== undefined
? innerCacheStore.explicitRevalidate ? innerCacheStore.explicitRevalidate
: innerCacheStore.revalidate : innerCacheStore.revalidate
const collectedExpire =
innerCacheStore.explicitExpire !== undefined
? innerCacheStore.explicitExpire
: innerCacheStore.expire
const collectedStale =
innerCacheStore.explicitStale !== undefined
? innerCacheStore.explicitStale
: innerCacheStore.stale
const entry = { const entry = {
value: bufferStream, value: bufferStream,
timestamp: startTime, timestamp: startTime,
revalidate: collectedRevalidate, revalidate: collectedRevalidate,
expire: Infinity, expire: collectedExpire,
stale: 0, stale: collectedStale,
tags: collectedTags === null ? [] : collectedTags, tags: collectedTags === null ? [] : collectedTags,
} }
// Propagate tags/revalidate to the parent context. // Propagate tags/revalidate to the parent context.
......
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