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
dde3976d
Commit
dde3976d
authored
Oct 19, 2025
by
Janka Uryga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow revalidate in cache handler, fix revalidate write
parent
66c194a5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
42 deletions
+66
-42
default.external.ts
...es/next/src/server/lib/cache-handlers/default.external.ts
+12
-10
use-cache-wrapper.ts
packages/next/src/server/use-cache/use-cache-wrapper.ts
+54
-32
No files found.
packages/next/src/server/lib/cache-handlers/default.external.ts
View file @
dde3976d
...
@@ -64,6 +64,7 @@ const DefaultCacheHandler: CacheHandler = {
...
@@ -64,6 +64,7 @@ const DefaultCacheHandler: CacheHandler = {
}
}
const
entry
=
privateEntry
.
entry
const
entry
=
privateEntry
.
entry
if
(
process
.
env
.
NODE_ENV
!==
'development'
)
{
if
(
if
(
performance
.
timeOrigin
+
performance
.
now
()
>
performance
.
timeOrigin
+
performance
.
now
()
>
entry
.
timestamp
+
entry
.
revalidate
*
1000
entry
.
timestamp
+
entry
.
revalidate
*
1000
...
@@ -75,6 +76,7 @@ const DefaultCacheHandler: CacheHandler = {
...
@@ -75,6 +76,7 @@ const DefaultCacheHandler: CacheHandler = {
return
undefined
return
undefined
}
}
}
let
revalidate
=
entry
.
revalidate
let
revalidate
=
entry
.
revalidate
...
...
packages/next/src/server/use-cache/use-cache-wrapper.ts
View file @
dde3976d
...
@@ -1508,6 +1508,7 @@ export function cache(
...
@@ -1508,6 +1508,7 @@ export function cache(
// If this is stale, and we're not in a prerender (i.e. this is
// If this is stale, and we're not in a prerender (i.e. this is
// dynamic render), then we should warm up the cache with a fresh
// dynamic render), then we should warm up the cache with a fresh
// revalidated entry.
// revalidated entry.
const
revalidateAndWriteNewEntry
=
async
()
=>
{
const
result
=
await
generateCacheEntry
(
const
result
=
await
generateCacheEntry
(
workStore
,
workStore
,
// This is not running within the context of this unit.
// This is not running within the context of this unit.
...
@@ -1522,7 +1523,20 @@ export function cache(
...
@@ -1522,7 +1523,20 @@ export function cache(
const
{
stream
:
ignoredStream
,
pendingCacheEntry
}
=
result
const
{
stream
:
ignoredStream
,
pendingCacheEntry
}
=
result
let
savedCacheEntry
:
Promise
<
CacheEntry
>
let
savedCacheEntry
:
Promise
<
CacheEntry
>
if
(
prerenderResumeDataCache
)
{
// TODO: do we ever want to mutate the `prerenderResumeDataCache` while a render is ongoing?
if
(
prerenderResumeDataCache
&&
// This is not covered by a cache read, so in a dev staged render
// we don't want to overwrite the existing cache entry
// both to avoid timing issues (with cache entries ehtat aren't finished yet) and tearing.
!
(
process
.
env
.
NODE_ENV
===
'development'
&&
workUnitStore
&&
// eslint-disable-next-line no-restricted-syntax
workUnitStore
.
type
===
'request'
&&
workUnitStore
.
stagedRendering
)
)
{
const
split
=
clonePendingCacheEntry
(
pendingCacheEntry
)
const
split
=
clonePendingCacheEntry
(
pendingCacheEntry
)
savedCacheEntry
=
getNthCacheEntry
(
split
,
0
)
savedCacheEntry
=
getNthCacheEntry
(
split
,
0
)
prerenderResumeDataCache
.
cache
.
set
(
prerenderResumeDataCache
.
cache
.
set
(
...
@@ -1533,19 +1547,27 @@ export function cache(
...
@@ -1533,19 +1547,27 @@ export function cache(
savedCacheEntry
=
pendingCacheEntry
savedCacheEntry
=
pendingCacheEntry
}
}
let
pendingWrite
:
Promise
<
void
>
|
undefined
if
(
cacheHandler
)
{
if
(
cacheHandler
)
{
const
promis
e
=
cacheHandler
.
set
(
pendingWrit
e
=
cacheHandler
.
set
(
serializedCacheKey
,
serializedCacheKey
,
savedCacheEntry
savedCacheEntry
)
)
workStore
.
pendingRevalidateWrites
??
=
[]
workStore
.
pendingRevalidateWrites
.
push
(
promise
)
}
}
await
ignoredStream
.
cancel
()
await
ignoredStream
.
cancel
()
return
pendingWrite
}
}
}
}
// TODO: ideally, this'd be scheduled to run after the render is finished
// to avoid interfering with any critical work.
const
pendingRevalidatePromise
=
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
)
).
then
(()
=>
revalidateAndWriteNewEntry
())
workStore
.
pendingRevalidateWrites
??
=
[]
workStore
.
pendingRevalidateWrites
.
push
(
pendingRevalidatePromise
)
}
}
}
}
}
...
...
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