Skip to content

Commit a2c2aa4

Browse files
committed
docs: fix pages router caching examples
1 parent 78aee79 commit a2c2aa4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,18 +385,14 @@ export default async function Page() {
385385
#### Page router
386386
```tsx
387387
import { evaluateFlags, flagsClient, getDefinitions } from "@unleash/nextjs";
388-
import {GetServerSideProps, NextPage} from "next";
388+
import type { GetServerSideProps, NextPage } from "next";
389389

390390
type Data = {
391391
isEnabled: boolean;
392392
};
393393

394394
export const getServerSideProps: GetServerSideProps<Data> = async () => {
395-
const definitions = await getDefinitions({
396-
fetchOptions: {
397-
next: { revalidate: 15 }, // Cache layer like Unleash Proxy!
398-
},
399-
});
395+
const definitions = await getDefinitions();
400396
const context = {};
401397
const { toggles } = evaluateFlags(definitions, context);
402398
const flags = flagsClient(toggles);

example/src/pages/ssr.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export const getServerSideProps: GetServerSideProps<Data> = async (ctx) => {
3535
"set-cookie",
3636
`${UNLEASH_COOKIE_NAME}=${sessionId}; path=/;`
3737
);
38+
ctx.res.setHeader(
39+
'Cache-Control', // In Pages Router you can cache entrie response, but not Unlaesh request only
40+
'public, s-maxage=10, stale-while-revalidate=59'
41+
)
3842

3943
const definitions = await getDefinitions();
4044
const { toggles } = evaluateFlags(definitions, {

0 commit comments

Comments
 (0)