Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
eb756a63
Unverified
Commit
eb756a63
authored
Aug 06, 2025
by
Janka Uryga
Committed by
GitHub
Aug 06, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Cache Components] give the "seconds" profile a 30s staleTime (#82332)
Closes NAR-262
parent
2dc45422
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
132 additions
and
27 deletions
+132
-27
config-shared.ts
packages/next/src/server/config-shared.ts
+1
-1
config.ts
packages/next/src/server/config.ts
+0
-12
page.tsx
...tch-runtime/app/(default)/caches/private-seconds/page.tsx
+33
-0
page.tsx
...etch-runtime/app/(default)/caches/public-seconds/page.tsx
+33
-0
page.tsx
.../(default)/caches/public-short-expire-long-stale/page.tsx
+1
-1
page.tsx
...dir/segment-cache/prefetch-runtime/app/(default)/page.tsx
+34
-0
prefetch-runtime.test.ts
...r/segment-cache/prefetch-runtime/prefetch-runtime.test.ts
+30
-13
No files found.
packages/next/src/server/config-shared.ts
View file @
eb756a63
...
@@ -1355,7 +1355,7 @@ export const defaultConfig = Object.freeze({
...
@@ -1355,7 +1355,7 @@ export const defaultConfig = Object.freeze({
expire
:
INFINITE_CACHE
,
expire
:
INFINITE_CACHE
,
},
},
seconds
:
{
seconds
:
{
stale
:
undefined
,
// defaults to staleTimes.dynamic
stale
:
30
,
// 30 seconds
revalidate
:
1
,
// 1 second
revalidate
:
1
,
// 1 second
expire
:
60
,
// 1 minute
expire
:
60
,
// 1 minute
},
},
...
...
packages/next/src/server/config.ts
View file @
eb756a63
...
@@ -942,18 +942,6 @@ function assignDefaults(
...
@@ -942,18 +942,6 @@ function assignDefaults(
result
.
expireTime
??
defaultDefault
.
expire
result
.
expireTime
??
defaultDefault
.
expire
}
}
}
}
// This is the most dynamic cache life profile.
const
secondsCacheLifeProfile
=
result
.
experimental
.
cacheLife
[
'seconds'
]
if
(
secondsCacheLifeProfile
&&
secondsCacheLifeProfile
.
stale
===
undefined
)
{
// We default this to whatever stale time you had configured for dynamic content.
// Since this is basically a dynamic cache life profile.
const
dynamicStaleTime
=
result
.
experimental
.
staleTimes
?.
dynamic
secondsCacheLifeProfile
.
stale
=
dynamicStaleTime
??
defaultConfig
.
experimental
?.
staleTimes
?.
dynamic
}
}
}
if
(
result
.
experimental
?.
cacheHandlers
)
{
if
(
result
.
experimental
?.
cacheHandlers
)
{
...
...
test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/caches/private-seconds/page.tsx
0 → 100644
View file @
eb756a63
import
{
Suspense
}
from
'react'
import
{
cachedDelay
,
DebugRenderKind
}
from
'../../../shared'
import
{
unstable_cacheLife
}
from
'next/cache'
export
default
async
function
Page
()
{
return
(
<
main
>
<
DebugRenderKind
/>
<
p
id=
"intro"
>
This page uses a short-lived private cache (with cacheLife("seconds")),
which should not be included in a static prefetch, but should be
included in a runtime prefetch, because it has a long enough stale time
(
≥
RUNTIME_PREFETCH_DYNAMIC_STALE, 30s)
</
p
>
<
Suspense
fallback=
{
<
div
style=
{
{
color
:
'grey'
}
}
>
Loading...
</
div
>
}
>
<
ShortLivedCache
/>
</
Suspense
>
</
main
>
)
}
async
function
ShortLivedCache
()
{
'use cache: private'
unstable_cacheLife
(
'seconds'
)
await
cachedDelay
([
__filename
])
return
(
<
div
style=
{
{
border
:
'1px solid blue'
,
padding
:
'1em'
}
}
>
Short-lived cached content
<
div
id=
"cached-value"
>
{
Date
.
now
()
}
</
div
>
</
div
>
)
}
test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/caches/public-seconds/page.tsx
0 → 100644
View file @
eb756a63
import
{
Suspense
}
from
'react'
import
{
cachedDelay
,
DebugRenderKind
}
from
'../../../shared'
import
{
unstable_cacheLife
}
from
'next/cache'
export
default
async
function
Page
()
{
return
(
<
main
>
<
DebugRenderKind
/>
<
p
id=
"intro"
>
This page uses a short-lived public cache (with cacheLife("seconds")),
which should not be included in a static prefetch, but should be
included in a runtime prefetch, because it has a long enough stale time
(
≥
RUNTIME_PREFETCH_DYNAMIC_STALE, 30s)
</
p
>
<
Suspense
fallback=
{
<
div
style=
{
{
color
:
'grey'
}
}
>
Loading...
</
div
>
}
>
<
ShortLivedCache
/>
</
Suspense
>
</
main
>
)
}
async
function
ShortLivedCache
()
{
'use cache'
unstable_cacheLife
(
'seconds'
)
await
cachedDelay
([
__filename
])
return
(
<
div
style=
{
{
border
:
'1px solid blue'
,
padding
:
'1em'
}
}
>
Short-lived cached content
<
div
id=
"cached-value"
>
{
Date
.
now
()
}
</
div
>
</
div
>
)
}
test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/caches/public-short-expire-long-stale/page.tsx
View file @
eb756a63
...
@@ -10,7 +10,7 @@ export default async function Page() {
...
@@ -10,7 +10,7 @@ export default async function Page() {
This page uses a short-lived public cache (expire
<
DYNAMIC_EXPIRE,
This page uses a short-lived public cache (expire
<
DYNAMIC_EXPIRE,
5min), which should not be included in a static prefetch, but should be
5min), which should not be included in a static prefetch, but should be
included in a runtime prefetch, because it has a long enough stale time
included in a runtime prefetch, because it has a long enough stale time
(
&g
t
;
RUNTIME_PREFETCH_DYNAMIC_STALE, 30s)
(
&g
e
;
RUNTIME_PREFETCH_DYNAMIC_STALE, 30s)
</
p
>
</
p
>
<
Suspense
fallback=
{
<
div
style=
{
{
color
:
'grey'
}
}
>
Loading...
</
div
>
}
>
<
Suspense
fallback=
{
<
div
style=
{
{
color
:
'grey'
}
}
>
Loading...
</
div
>
}
>
<
ShortLivedCache
/>
<
ShortLivedCache
/>
...
...
test/e2e/app-dir/segment-cache/prefetch-runtime/app/(default)/page.tsx
View file @
eb756a63
...
@@ -189,6 +189,40 @@ export default async function Page() {
...
@@ -189,6 +189,40 @@ export default async function Page() {
</
li
>
</
li
>
</
ul
>
</
ul
>
</
li
>
</
li
>
<
li
>
public, cacheLife("seconds")
<
ul
>
<
li
>
<
DebugLinkAccordion
href=
"/caches/public-seconds"
prefetch=
{
'auto'
}
/>
</
li
>
<
li
>
<
DebugLinkAccordion
href=
"/caches/public-seconds"
prefetch=
{
true
}
/>
</
li
>
</
ul
>
</
li
>
<
li
>
private, cacheLife("seconds")
<
ul
>
<
li
>
<
DebugLinkAccordion
href=
"/caches/private-seconds"
prefetch=
{
'auto'
}
/>
</
li
>
<
li
>
<
DebugLinkAccordion
href=
"/caches/private-seconds"
prefetch=
{
true
}
/>
</
li
>
</
ul
>
</
li
>
</
ul
>
</
ul
>
<
h2
>
misc
</
h2
>
<
h2
>
misc
</
h2
>
...
...
test/e2e/app-dir/segment-cache/prefetch-runtime/prefetch-runtime.test.ts
View file @
eb756a63
...
@@ -670,10 +670,32 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
...
@@ -670,10 +670,32 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
})
})
describe
(
'cache stale time handling'
,
()
=>
{
describe
(
'cache stale time handling'
,
()
=>
{
it
(
'includes short-lived public caches with a long enough staleTime'
,
async
()
=>
{
it
.
each
([
{
// If a cache has an expiration time under 5min (DYNAMIC_EXPIRE), we omit it from static prerenders.
// If a cache has an expiration time under 5min (DYNAMIC_EXPIRE), we omit it from static prerenders.
// However, it should still be included in a runtime prefetch if it's stale time is above 30s. (RUNTIME_PREFETCH_DYNAMIC_STALE)
// However, it should still be included in a runtime prefetch if its stale time is >=30s. (RUNTIME_PREFETCH_DYNAMIC_STALE)
description
:
'includes short-lived public caches with a long enough staleTime'
,
staticContent
:
'This page uses a short-lived public cache'
,
path
:
'/caches/public-short-expire-long-stale'
,
},
{
// If a cache has an expiration time under 5min (DYNAMIC_EXPIRE), we omit it from static prerenders.
// However, it should still be included in a runtime prefetch if its stale time is >=30s. (RUNTIME_PREFETCH_DYNAMIC_STALE)
// `cacheLife("seconds")` is deliberately set to have a stale time of 30s to stay above this treshold.
description
:
'includes public caches with cacheLife("seconds")'
,
staticContent
:
'This page uses a short-lived public cache'
,
path
:
'/caches/public-seconds'
,
},
{
// A Private cache will always be omitted from static prerenders.
// However, it should still be included in a runtime prefetch if its stale time is >=30s. (RUNTIME_PREFETCH_DYNAMIC_STALE)
// `cacheLife("seconds")` is deliberately set to have a stale time of 30s to stay above this treshold.
description
:
'includes private caches with cacheLife("seconds")'
,
staticContent
:
'This page uses a short-lived private cache'
,
path
:
'/caches/private-seconds'
,
},
])(
'$description'
,
async
({
path
,
staticContent
})
=>
{
let
page
:
Playwright
.
Page
let
page
:
Playwright
.
Page
const
browser
=
await
next
.
browser
(
'/'
,
{
const
browser
=
await
next
.
browser
(
'/'
,
{
beforePageLoad
(
p
:
Playwright
.
Page
)
{
beforePageLoad
(
p
:
Playwright
.
Page
)
{
...
@@ -682,22 +704,20 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
...
@@ -682,22 +704,20 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
})
})
const
act
=
createRouterAct
(
page
)
const
act
=
createRouterAct
(
page
)
const
STATIC_CONTENT
=
'This page uses a short-lived public cache'
const
DYNAMICALLY_PREFETCHABLE_CONTENT
=
'Short-lived cached content'
const
DYNAMICALLY_PREFETCHABLE_CONTENT
=
'Short-lived cached content'
// Reveal the link to trigger a static prefetch
// Reveal the link to trigger a static prefetch
await
act
(
async
()
=>
{
await
act
(
async
()
=>
{
const
linkToggle
=
await
browser
.
elementByCss
(
const
linkToggle
=
await
browser
.
elementByCss
(
`input[data-prefetch="auto"][data-link-accordion="
/caches/public-short-expire-long-stale
"]`
`input[data-prefetch="auto"][data-link-accordion="
${
path
}
"]`
)
)
await
linkToggle
.
click
()
await
linkToggle
.
click
()
},
[
},
[
// Should include the static shell
// Should include the static shell
{
{
includes
:
STATIC_CONTENT
,
includes
:
staticContent
,
},
},
// Should not include the short-lived cache
// Should not include the short-lived cache
// (We set the `expire` value to be under 5min, so it will be excluded from prerenders)
{
{
includes
:
DYNAMICALLY_PREFETCHABLE_CONTENT
,
includes
:
DYNAMICALLY_PREFETCHABLE_CONTENT
,
block
:
'reject'
,
block
:
'reject'
,
...
@@ -707,12 +727,11 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
...
@@ -707,12 +727,11 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
// Reveal the link to trigger a runtime prefetch
// Reveal the link to trigger a runtime prefetch
await
act
(
async
()
=>
{
await
act
(
async
()
=>
{
const
linkToggle
=
await
browser
.
elementByCss
(
const
linkToggle
=
await
browser
.
elementByCss
(
`input[data-prefetch="runtime"][data-link-accordion="
/caches/public-short-expire-long-stale
"]`
`input[data-prefetch="runtime"][data-link-accordion="
${
path
}
"]`
)
)
await
linkToggle
.
click
()
await
linkToggle
.
click
()
},
[
},
[
// Should include the short-lived cache
// Should include the short-lived cache
// (We set `stale` to be above 30s, which means it shouldn't be omitted)
{
{
includes
:
DYNAMICALLY_PREFETCHABLE_CONTENT
,
includes
:
DYNAMICALLY_PREFETCHABLE_CONTENT
,
},
},
...
@@ -721,9 +740,7 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
...
@@ -721,9 +740,7 @@ describe('<Link prefetch={true}> (runtime prefetch)', () => {
// Navigate to the page. We didn't include any uncached IO, so the page is fully prefetched,
// Navigate to the page. We didn't include any uncached IO, so the page is fully prefetched,
// and this shouldn't issue any more requests
// and this shouldn't issue any more requests
await
act
(
async
()
=>
{
await
act
(
async
()
=>
{
await
browser
await
browser
.
elementByCss
(
`a[href="
${
path
}
"]`
).
click
()
.
elementByCss
(
`a[href="/caches/public-short-expire-long-stale"]`
)
.
click
()
},
'no-requests'
)
},
'no-requests'
)
expect
(
await
browser
.
elementByCss
(
'main'
).
text
()).
toInclude
(
expect
(
await
browser
.
elementByCss
(
'main'
).
text
()).
toInclude
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment