File tree Expand file tree Collapse file tree 1 file changed +22
-9
lines changed
src/app/(builder)/components Expand file tree Collapse file tree 1 file changed +22
-9
lines changed Original file line number Diff line number Diff line change 1
1
import { builder } from "@builder.io/sdk" ;
2
+ import { unstable_cache } from "next/cache" ;
2
3
import Head from "next/head" ;
3
4
4
5
import { RenderBuilderContent } from "./RenderBuilderContent" ;
@@ -8,18 +9,30 @@ interface BuilderPageProps {
8
9
page : string [ ] ;
9
10
}
10
11
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
+
11
32
export const BuilderPage = async ( { data, page } : BuilderPageProps ) => {
12
33
builder . init ( process . env . NEXT_PUBLIC_BUILDER_IO_PUBLIC_KEY ! ) ;
13
34
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 ( "/" ) || "" ) ) ( ) ;
23
36
return (
24
37
< >
25
38
< Head >
You can’t perform that action at this time.
0 commit comments