| | import type { PrerenderManifest } from '../../../build' |
| | import type { DeepReadonly } from '../../../shared/lib/deep-readonly' |
| | import type { CacheControl } from '../cache-control' |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export class SharedCacheControls { |
| | |
| | |
| | |
| | |
| | private static readonly cacheControls = new Map<string, CacheControl>() |
| |
|
| | constructor( |
| | |
| | |
| | |
| | |
| | private readonly prerenderManifest: DeepReadonly< |
| | Pick<PrerenderManifest, 'routes' | 'dynamicRoutes'> |
| | > |
| | ) {} |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public get(route: string): CacheControl | undefined { |
| | |
| | |
| | |
| | let cacheControl = SharedCacheControls.cacheControls.get(route) |
| | if (cacheControl) return cacheControl |
| |
|
| | let prerenderData = this.prerenderManifest.routes[route] |
| |
|
| | if (prerenderData) { |
| | const { initialRevalidateSeconds, initialExpireSeconds } = prerenderData |
| |
|
| | if (typeof initialRevalidateSeconds !== 'undefined') { |
| | return { |
| | revalidate: initialRevalidateSeconds, |
| | expire: initialExpireSeconds, |
| | } |
| | } |
| | } |
| |
|
| | const dynamicPrerenderData = this.prerenderManifest.dynamicRoutes[route] |
| |
|
| | if (dynamicPrerenderData) { |
| | const { fallbackRevalidate, fallbackExpire } = dynamicPrerenderData |
| |
|
| | if (typeof fallbackRevalidate !== 'undefined') { |
| | return { revalidate: fallbackRevalidate, expire: fallbackExpire } |
| | } |
| | } |
| |
|
| | return undefined |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public set(route: string, cacheControl: CacheControl) { |
| | SharedCacheControls.cacheControls.set(route, cacheControl) |
| | } |
| |
|
| | |
| | |
| | |
| | public clear() { |
| | SharedCacheControls.cacheControls.clear() |
| | } |
| | } |
| |
|