|
| 1 | +import type { |
| 2 | + CacheHandlerValue, |
| 3 | + IncrementalCacheContext, |
| 4 | + IncrementalCacheValue, |
| 5 | +} from "types/cache"; |
1 | 6 | import { isBinaryContentType } from "../utils/binary"; |
2 | 7 | import { debug, error, warn } from "./logger"; |
3 | 8 | import { getTagFromValue, hasBeenRevalidated } from "utils/cache"; |
4 | 9 |
|
5 | | -interface CachedFetchValue { |
6 | | - kind: "FETCH"; |
7 | | - data: { |
8 | | - headers: { [k: string]: string }; |
9 | | - body: string; |
10 | | - url: string; |
11 | | - status?: number; |
12 | | - tags?: string[]; |
13 | | - }; |
14 | | - revalidate: number; |
15 | | -} |
16 | | - |
17 | | -interface CachedRedirectValue { |
18 | | - kind: "REDIRECT"; |
19 | | - props: Object; |
20 | | -} |
21 | | - |
22 | | -interface CachedRouteValue { |
23 | | - kind: "ROUTE" | "APP_ROUTE"; |
24 | | - // this needs to be a RenderResult so since renderResponse |
25 | | - // expects that type instead of a string |
26 | | - body: Buffer; |
27 | | - status: number; |
28 | | - headers: Record<string, undefined | string | string[]>; |
29 | | -} |
30 | | - |
31 | | -interface CachedImageValue { |
32 | | - kind: "IMAGE"; |
33 | | - etag: string; |
34 | | - buffer: Buffer; |
35 | | - extension: string; |
36 | | - isMiss?: boolean; |
37 | | - isStale?: boolean; |
38 | | -} |
39 | | - |
40 | | -interface IncrementalCachedPageValue { |
41 | | - kind: "PAGE" | "PAGES"; |
42 | | - // this needs to be a string since the cache expects to store |
43 | | - // the string value |
44 | | - html: string; |
45 | | - pageData: Object; |
46 | | - status?: number; |
47 | | - headers?: Record<string, undefined | string>; |
48 | | -} |
49 | | - |
50 | | -interface IncrementalCachedAppPageValue { |
51 | | - kind: "APP_PAGE"; |
52 | | - // this needs to be a string since the cache expects to store |
53 | | - // the string value |
54 | | - html: string; |
55 | | - rscData: Buffer; |
56 | | - headers?: Record<string, undefined | string | string[]>; |
57 | | - postponed?: string; |
58 | | - status?: number; |
59 | | -} |
60 | | - |
61 | | -type IncrementalCacheValue = |
62 | | - | CachedRedirectValue |
63 | | - | IncrementalCachedPageValue |
64 | | - | IncrementalCachedAppPageValue |
65 | | - | CachedImageValue |
66 | | - | CachedFetchValue |
67 | | - | CachedRouteValue; |
68 | | - |
69 | | -type IncrementalCacheContext = { |
70 | | - revalidate?: number | false | undefined; |
71 | | - fetchCache?: boolean | undefined; |
72 | | - fetchUrl?: string | undefined; |
73 | | - fetchIdx?: number | undefined; |
74 | | - tags?: string[] | undefined; |
75 | | -}; |
76 | | - |
77 | | -interface CacheHandlerValue { |
78 | | - lastModified?: number; |
79 | | - age?: number; |
80 | | - cacheState?: string; |
81 | | - value: IncrementalCacheValue | null; |
82 | | -} |
83 | | - |
84 | 10 | function isFetchCache( |
85 | 11 | options?: |
86 | 12 | | boolean |
|
0 commit comments