Skip to content

Commit 84f0a32

Browse files
committed
Cache things for an hour
1 parent 89693b5 commit 84f0a32

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

app/routes/$libraryId/$version.docs.framework.$framework.examples.$.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const repoDirApiContentsQueryOptions = (
4343
fetchRepoDirectoryContents({
4444
data: { repo, branch, startingPath },
4545
}),
46+
staleTime: Infinity,
4647
})
4748

4849
export const Route = createFileRoute(

app/utils/docs.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ export const fetchFile = createServerFn({ method: 'GET' })
100100
throw notFound()
101101
}
102102

103-
// // Cache for 5 minutes on shared cache
104-
// // Revalidate in the background
105-
// setHeader('Cache-Control', 'public, max-age=0, must-revalidate')
106-
// setHeader(
107-
// 'CDN-Cache-Control',
108-
// 'max-age=300, stale-while-revalidate=300, durable'
109-
// )
103+
// Cache for 60 minutes on shared cache
104+
// Revalidate in the background
105+
setHeader('Cache-Control', 'public, max-age=0, must-revalidate')
106+
setHeader(
107+
'CDN-Cache-Control',
108+
'max-age=3600, stale-while-revalidate=3600, durable'
109+
)
110110

111111
return file
112112
})
@@ -123,5 +123,14 @@ export const fetchRepoDirectoryContents = createServerFn({
123123
)
124124
.handler(async ({ data: { repo, branch, startingPath } }) => {
125125
const githubContents = await fetchApiContents(repo, branch, startingPath)
126+
127+
// Cache for 60 minutes on shared cache
128+
// Revalidate in the background
129+
setHeader('Cache-Control', 'public, max-age=0, must-revalidate')
130+
setHeader(
131+
'CDN-Cache-Control',
132+
'max-age=3600, stale-while-revalidate=3600, durable'
133+
)
134+
126135
return githubContents
127136
})

0 commit comments

Comments
 (0)