
6 July 2025
Where: Server
Duration: Untill React has finish rendering
Purpose: Re-use data in React component tree
React feature, applies to the GET request
Don't apple to router handler
What is
Where: Server Duration: Persistent unless revalidate or opt-out Purpose: Store data across request
An request send, if a cached found, it return immediately if a cached not found, the request is made to the date source and store in the Data Cache
Difference with Request Memoization, Data cached is persistent across incoming requests and deployement, whereas memoization only in the same render
Revaliate
Time base: use 'revalidate = 10'
On-Demand: use revalidateTag or revalidatePath
Opt-out
fetch(https://..., { cache: 'no-store' })What is
Where: Server Purpose: HTML and RSC (React Server Compoent) payload for faster page load Duration: By default it persistent
Only cached static render route Unlike Date Cache across the deployments, the Full Route Cache will purge in new deploy
Revalidate Revalidate the Data Cached
Opting out
fetch(https://..., { cache: 'no-store' })What is
Where: Client Purpose: Reduce server request when navigation Duration:
Client-side Cached include both visited and prefetched Unlike Full Route Cached, it temparory store RSC payload in the browser, whereas Full Route Cached store persistent store RSC payload and HTML Apply to both static and dynamic route
Revalidte
route.refresh(): will make the new request for the current route, do not affect the Data or Full Route Cache
dynamic = 'force-dynamic': Opt-out Date and Full Route Cache
revalidate = 0: Opt-out Date and Full Route Cache
Dynamic function like 'header'...: Opt-out Full Route Cache, in other words, the route will dynamic rerender
revalidateTag, revalidatePath: Revalidate the Data and Full Route Cache
jwt({toke, user}), take user inputssession({token, session}), store user inputs with custom formatimport { ThemeProvider } from "next-themes";
// wrap whole body of main layout
<html lang="en" suppressHydrationWarning>
<body>
<ThemeProvider attribute="class">
...suppressHydrationWarning: It is used when the server-rendered HTML deliberately differs from the client-rendered output
Toggle theme button
import { useTheme } from "next-themes";
const { setTheme, theme } = useTheme();
const [isMount, setIsMount] = useState(false);
useEffect(() => {
if (!isMount) setIsMount(true);
}, []);
...
<button
onClick={() => setTheme(theme === "light" ? "dark" : "light")}
className=""
>
Make with
by Nguyen Huu Dat
© 2025