Skip to content

Commit 09b9110

Browse files
committed
feat: implement caching for BuilderPage using unstable_cache
1 parent 66ffb9d commit 09b9110

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/app/(builder)/components/BuilderPage.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { builder } from "@builder.io/sdk";
2+
import { unstable_cache } from "next/cache";
23
import Head from "next/head";
34

45
import { RenderBuilderContent } from "./RenderBuilderContent";
@@ -8,18 +9,30 @@ interface BuilderPageProps {
89
page: string[];
910
}
1011

12+
const getCachedBuilderPage = (urlPath: string) => {
13+
return unstable_cache(
14+
() =>
15+
builder
16+
.get("page", {
17+
cache: true,
18+
prerender: false,
19+
userAttributes: {
20+
urlPath,
21+
},
22+
})
23+
.toPromise(),
24+
["builder-page", urlPath],
25+
{
26+
revalidate: 60,
27+
tags: ["builder-page", `builder-page:${urlPath}`],
28+
}
29+
);
30+
};
31+
1132
export const BuilderPage = async ({ data, page }: BuilderPageProps) => {
1233
builder.init(process.env.NEXT_PUBLIC_BUILDER_IO_PUBLIC_KEY!);
1334

14-
const content = await builder
15-
.get("page", {
16-
cache: true,
17-
prerender: false,
18-
userAttributes: {
19-
urlPath: "/" + (page?.join("/") || ""),
20-
},
21-
})
22-
.toPromise();
35+
const content = await getCachedBuilderPage("/" + (page?.join("/") || ""))();
2336
return (
2437
<>
2538
<Head>

0 commit comments

Comments
 (0)