Demo
Cached Functions
- Mark a regular function as cacheable by adding the
use cachedirective to the top of the function definition. - When a cacheable function is called with the same inputs, it reuses the cached result if it exists, otherwise it runs and caches the output.
app/page.tsx
1async function getData() {2'use cache';3// ...4}56async function ProductList() {7const products = await getData();8// ...9}1011export default async function Page() {12return <ProductList />;13}
Demo
- The data fetching function to get the list of products is annotated with
use cache. - An artificial one second delay is added to the function to make the difference more noticeable.
- Since the function is cacheable, the delay only happens the first time the function is called.
layout.tsx,page.tsxand<ProductList>aren't explicitly annotated withuse cache, but Next.js infers they're static because they do not use any Dynamic APIs. If they started to, Next.js will guide the developer to either adduse cacheor a<Suspense>boundary.
Notes
- This demo uses the experimental
use cachedirective and describes caching behavior once stable.
layout.tsx (statically inferred)
page.tsx (statically inferred)
<ProductList> (statically inferred)
All (9)








