Skip to content

Commit 019435c

Browse files
authored
Merge pull request #230 from dotCMS/fixing-isr-caching
fixing isr caching
2 parents 7cdf9ee + 2b21226 commit 019435c

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

app/docs/[slug]/page.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { notFound } from "next/navigation";
22
import { getDotCMSPage } from "@/util/getDotCMSPage";
3+
4+
// ISR: Revalidate pages every 60 seconds
5+
export const revalidate = 60;
36
import { getSideNav } from "@/services/docs/getSideNav"
47
import { isGitHubDoc, getGitHubConfig } from "@/config/github-docs";
58
import { getDocsContentWithGitHub } from "@/services/docs/getGitHubContent";

services/docs/getNavSections.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ export async function getNavSections(options: FetchOptions = {}): Promise<NavSec
4747
const res = await fetch(url, {
4848
method: 'GET',
4949
headers: Config.Headers,
50-
// Ensure server-side request cache doesn't interfere; we manage our own cache
51-
cache: 'no-store',
52-
next: { revalidate: 0 },
50+
// Use Next.js data cache with revalidation (works in serverless)
51+
// In-memory navCache above provides request-level deduplication
52+
next: { revalidate: ttlSeconds },
5353
});
5454

5555
if (!res.ok) {

services/renders/getGraphQLPageQuery/getGraphQLPageQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const getGraphQLPageQuery = async ({
9494
method: 'POST',
9595
headers: Config.Headers,
9696
body: JSON.stringify({ query }),
97-
cache: 'no-cache'
97+
next: { revalidate: 60 } // ISR: revalidate every 60 seconds
9898
}),
9999
'getGraphQLPageQuery'
100100
);

util/dotcmsClient.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export const client = createDotCMSClient({
1515
authToken: authToken,
1616
siteId: "173aff42881a55a562cec436180999cf",
1717
requestOptions: {
18-
// In production you might want to deal with this differently
19-
cache: "no-cache",
18+
next: { revalidate: 60 } // ISR: revalidate cached data every 60 seconds
2019
}
2120
});

0 commit comments

Comments
 (0)