Skip to content

Commit c7a8fe0

Browse files
committed
cleanup cache
1 parent ea19789 commit c7a8fe0

File tree

2 files changed

+28
-83
lines changed

2 files changed

+28
-83
lines changed

packages/open-next/src/adapters/cache.ts

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,12 @@
1+
import type {
2+
CacheHandlerValue,
3+
IncrementalCacheContext,
4+
IncrementalCacheValue,
5+
} from "types/cache";
16
import { isBinaryContentType } from "../utils/binary";
27
import { debug, error, warn } from "./logger";
38
import { getTagFromValue, hasBeenRevalidated } from "utils/cache";
49

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-
8410
function isFetchCache(
8511
options?:
8612
| boolean

packages/open-next/src/types/cache.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface CachedRedirectValue {
1616
}
1717

1818
interface CachedRouteValue {
19-
kind: "ROUTE";
19+
kind: "ROUTE" | "APP_ROUTE";
2020
// this needs to be a RenderResult so since renderResponse
2121
// expects that type instead of a string
2222
body: Buffer;
@@ -34,7 +34,7 @@ interface CachedImageValue {
3434
}
3535

3636
interface IncrementalCachedPageValue {
37-
kind: "PAGE";
37+
kind: "PAGE" | "PAGES";
3838
// this needs to be a string since the cache expects to store
3939
// the string value
4040
html: string;
@@ -43,9 +43,21 @@ interface IncrementalCachedPageValue {
4343
headers?: Record<string, undefined | string>;
4444
}
4545

46-
type IncrementalCacheValue =
46+
interface IncrementalCachedAppPageValue {
47+
kind: "APP_PAGE";
48+
// this needs to be a string since the cache expects to store
49+
// the string value
50+
html: string;
51+
rscData: Buffer;
52+
headers?: Record<string, undefined | string | string[]>;
53+
postponed?: string;
54+
status?: number;
55+
}
56+
57+
export type IncrementalCacheValue =
4758
| CachedRedirectValue
4859
| IncrementalCachedPageValue
60+
| IncrementalCachedAppPageValue
4961
| CachedImageValue
5062
| CachedFetchValue
5163
| CachedRouteValue;
@@ -60,7 +72,6 @@ export interface CacheHandlerContext {
6072
_requestHeaders: never;
6173
fetchCacheKeyPrefix?: string;
6274
}
63-
6475
export interface CacheHandlerValue {
6576
lastModified?: number;
6677
age?: number;
@@ -80,3 +91,11 @@ export interface Meta {
8091
headers?: MetaHeaders;
8192
postponed?: string;
8293
}
94+
95+
export type IncrementalCacheContext = {
96+
revalidate?: number | false | undefined;
97+
fetchCache?: boolean | undefined;
98+
fetchUrl?: string | undefined;
99+
fetchIdx?: number | undefined;
100+
tags?: string[] | undefined;
101+
};

0 commit comments

Comments
 (0)