{post.title}
-{post.content}
-
+ cache: "force-cache"
+ {" "}
+ for fetch requests
+
+ force-cache
+
+
+ revalidate: 86400
+
+ )
+
+ "futurama"
+ {" "}
+ for selective invalidation
+
+ futurama
+
+
+ generateStaticParams
+ {" "}
+ generates static paths at build time
+
+ revalidate: 3600
+
+ )
+ + {post.content} +
+
+ cache: "no-store"
+ {" "}
+ tells Next.js to never cache the response
+
+ no-store
+
+
+ revalidateTag(tag)
+
+
+ revalidateTag(tag, cacheLife)
+ {" "}
+ - cacheLife is now required
+
+ cacheLife
+ {" "}
+ parameter enables stale-while-revalidate behavior
+
+ 'max'
+
+ ,{" "}
+
+ 'hours'
+
+ ,{" "}
+
+ 'days'
+
+
+ Note: The{" "}
+
+ cacheLife
+ {" "}
+ parameter is handled by Next.js internally and is not directly
+ exposed to custom cache handlers.
+
+ There are two different cache handler APIs in + Next.js 16: +
+
+ fetch
+
+ ,{" "}
+
+ revalidateTag
+
+ , ISR, etc. Implements{" "}
+
+ revalidateTag(tag: string)
+ {" "}
+ - does not receive{" "}
+
+ cacheLife
+
+ .
+
+ 'use cache'
+ {" "}
+ directive): Implements{" "}
+
+ updateTags(tags, durations)
+ {" "}
+ with{" "}
+
+ durations.expire
+
+ , but this is a different mechanism and not the same as{" "}
+
+ cacheLife
+ {" "}
+ profiles.
+
+ The{" "}
+
+ cacheLife
+ {" "}
+ parameter for{" "}
+
+ revalidateTag()
+ {" "}
+ is processed by Next.js core and primarily affects
+ stale-while-revalidate behavior on Vercel's infrastructure.
+ Custom handlers may not fully differentiate between different{" "}
+
+ cacheLife
+ {" "}
+ profiles.
+
+ Reference:{" "} + + Next.js cacheHandlers documentation + +
++ Maximum cache life - serves stale content while revalidating in + the background +
++ Hourly cache life - good balance for frequently updated content +
++ Daily cache life - for content that changes infrequently +
++ 'max': Maximum cache life. Serves stale + content while revalidating in the background. Best for content + that can tolerate being slightly stale. +
++ 'hours': Hourly cache life. Good for + content that updates frequently but doesn't need to be + real-time. +
++ 'days': Daily cache life. Perfect for + content that changes infrequently, like blog posts or product + catalogs. +
+
+ Stale-while-revalidate: When you call{" "}
+
+ revalidateTag()
+
+ , Next.js serves the stale cached content immediately while
+ revalidating in the background. This ensures fast responses while
+ keeping content fresh.
+
+ generateStaticParams
+ {" "}
+ generates the "cache" route at build time
+
+ dynamicParams: true
+ {" "}
+ allows other dynamic routes to be generated on demand
+
+ /examples/static-params/test1
+ {" "}
+ or{" "}
+
+ /examples/static-params/test2
+
+
+ next: { revalidate: 30 }
+ {" "}
+ caches data for 30 seconds
+
+ Time-based ISR
+
+ + The timestamp will remain the same for 30 seconds. After that, + the next request will fetch fresh data. +
+
+ unstable_cache
+ {" "}
+ caches the result of function calls across requests
+
+ futurama
+
+
+ characters
+
+ + When to use unstable_cache: When you need to + cache the result of database queries, complex computations, or any + non-fetch operations. When you need more control over cache keys. +
+
+ updateTag()
+ {" "}
+ provides immediate cache invalidation within Server Actions
+
+ revalidateTag()
+
+ , it immediately expires the cache, forcing the next request to
+ fetch fresh data
+ | + Feature + | ++ updateTag() + | ++ revalidateTag() + | +
|---|---|---|
| + Usage + | ++ Server Actions only + | ++ Server Actions & Route Handlers + | +
| + Cache Behavior + | ++ Immediately expires cache + | ++ Marks as stale, serves stale while revalidating + | +
| + Next Request + | ++ Always fetches fresh data + | ++ May serve stale content during revalidation + | +
| + Use Case + | ++ Immediate consistency (forms, settings) + | ++ Background updates (catalogs, blogs) + | +
| + Read-your-writes + | ++ ✅ Guaranteed + | ++ ❌ Not guaranteed + | +
+ This form uses{" "}
+
+ updateTag()
+ {" "}
+ to immediately invalidate the cache after creating a new post. The
+ new post appears instantly without stale content.
+
+ Current posts (cached with tag: "posts") +
+
+ User settings are cached with the "user-profile" tag.
+ When you update settings,{" "}
+
+ updateTag()
+ {" "}
+ ensures your changes are immediately visible.
+
+ Current profile (cached with tag: "user-profile") +
+
+ updateTag()
+ {" "}
+ in Server Actions when you need immediate cache invalidation after
+ mutations
+
+ revalidateTag()
+
+ , it immediately expires the cache rather than using
+ stale-while-revalidate
+
+ updateTag()
+ {" "}
+ will always fetch fresh data from the source
+ {post.content}
-