Skip to content

Commit 318355a

Browse files
committed
Add caching to example files
1 parent ca471d7 commit 318355a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
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
@@ -28,6 +28,7 @@ const fileQueryOptions = (repo: string, branch: string, filePath: string) => {
2828
fetchFile({
2929
data: { repo, branch, filePath },
3030
}),
31+
staleTime: Infinity, // We can cache this forever. A refresh can invalidate the cache if necessary.
3132
})
3233
}
3334

app/utils/docs.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ 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+
)
110+
103111
return file
104112
})
105113

0 commit comments

Comments
 (0)