Skip to content

Commit fd3c538

Browse files
author
Aviv Keller
authored
fix(cache): remove cache rules from fetch() (#7270)
1 parent 881afd4 commit fd3c538

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

apps/site/app/[locale]/next-data/api-data/route.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ export const GET = async () => {
2929

3030
const gitHubApiResponse = await fetch(
3131
getGitHubApiDocsUrl(versionWithPrefix),
32-
{ ...authorizationHeaders, cache: 'force-cache' }
32+
authorizationHeaders
3333
);
3434

3535
return gitHubApiResponse.json().then((apiDocsFiles: Array<GitHubApiFile>) => {
3636
// maps over each api file and get the download_url, fetch the content and deflates it
3737
const mappedApiFiles = apiDocsFiles.map(
3838
async ({ name, path: filename, download_url }) => {
39-
const apiFileResponse = await fetch(download_url, {
40-
cache: 'force-cache',
41-
});
39+
const apiFileResponse = await fetch(download_url);
4240

4341
// Retrieves the content as a raw text string
4442
const source = await apiFileResponse.text();

apps/site/next-data/blogData.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ const getBlogData = (cat: string, page?: number): Promise<BlogPostsRSC> => {
2525

2626
const fetchURL = `${NEXT_DATA_URL}blog-data/${cat}/${page ?? 0}`;
2727

28-
// When we're on RSC with Server capabilities we prefer using Next.js Data Fetching
29-
// as this will load cached data from the server instead of generating data on the fly
30-
// this is extremely useful for ISR and SSG as it will not generate this data on every request
31-
return fetch(fetchURL, { cache: 'force-cache' })
28+
// This data cannot be cached because it is continuously updated. Caching it would lead to
29+
// outdated information being shown to the user.
30+
return fetch(fetchURL)
3231
.then(response => response.text())
3332
.then(response => parseBlogDataResponse(response));
3433
};

apps/site/next-data/releaseData.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ const getReleaseData = (): Promise<Array<NodeRelease>> => {
1919

2020
const fetchURL = `${NEXT_DATA_URL}release-data`;
2121

22-
// When we're on RSC with Server capabilities we prefer using Next.js Data Fetching
23-
// as this will load cached data from the server instead of generating data on the fly
24-
// this is extremely useful for ISR and SSG as it will not generate this data on every request
22+
// This data cannot be cached because it is continuously updated. Caching it would lead to
23+
// outdated information being shown to the user.
2524
// Note: We do manual JSON.parse after response.text() to prevent React from throwing an Error
2625
// that does not provide a clear stack trace of which request is failing and what the JSON.parse error is
27-
return fetch(fetchURL, { cache: 'force-cache' })
26+
return fetch(fetchURL)
2827
.then(response => response.text())
2928
.then(JSON.parse);
3029
};

apps/site/next.calendar.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const getCalendarEvents = async (calendarId = '', maxResults = 20) => {
3333
calendarQueryUrl.searchParams.append(key, value)
3434
);
3535

36-
return fetch(calendarQueryUrl, { cache: 'force-cache' })
36+
return fetch(calendarQueryUrl)
3737
.then(response => response.json())
3838
.then(calendar => calendar.items ?? []);
3939
};

0 commit comments

Comments
 (0)