Skip to content

Commit a6229f4

Browse files
committed
fix: update cache control headers and enable staleOnError in fetchCached
1 parent 12dd0e6 commit a6229f4

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const repoDirApiContentsQueryOptions = (
5252
export const Route = createFileRoute(
5353
'/$libraryId/$version/docs/framework/$framework/examples/$',
5454
)({
55-
component: RouteComponent,
5655
validateSearch: v.object({
5756
path: v.optional(v.string()),
5857
panel: v.optional(v.string()),
@@ -125,6 +124,32 @@ export const Route = createFileRoute(
125124
}),
126125
}
127126
},
127+
component: RouteComponent,
128+
headers: ({ params }) => {
129+
const { version, libraryId } = params
130+
const library = getLibrary(libraryId)
131+
132+
const isLatestVersion =
133+
version === 'latest' ||
134+
version === library.latestVersion ||
135+
version === library.latestBranch
136+
137+
if (isLatestVersion) {
138+
return {
139+
'cache-control': 'public, max-age=60, must-revalidate',
140+
'cdn-cache-control':
141+
'max-age=600, stale-while-revalidate=3600, durable',
142+
vary: 'Accept-Encoding',
143+
}
144+
}
145+
146+
return {
147+
'cache-control': 'public, max-age=3600, must-revalidate',
148+
'cdn-cache-control':
149+
'max-age=86400, stale-while-revalidate=604800, durable',
150+
vary: 'Accept-Encoding',
151+
}
152+
},
128153
staleTime: 1000 * 60 * 5, // 5 minutes
129154
})
130155

src/utils/documents.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export async function fetchRepoFile(
287287
const file = await fetchCached({
288288
key,
289289
ttl,
290+
staleOnError: true,
290291
fn: async () => {
291292
const maxDepth = 4
292293
let currentDepth = 1

0 commit comments

Comments
 (0)