-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure fetch cache TTL is updated properly (#69164)
To reduce the number of set requests we were sending upstream we added an optimization to skip sending the set request if the cached data didn't change after a revalidation. The problem with this optimization is the upstream service relies on this set request to know to update the cache entries TTL and consider it up to date. This causes unexpected revalidations while the cache value hasn't changed and the TTL is kept stale. x-ref: NEXT-3693
- Loading branch information
Showing
5 changed files
with
90 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
test/production/app-dir/fetch-cache/app/not-changed/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { unstable_cache } from 'next/cache' | ||
|
||
export const dynamic = 'force-dynamic' | ||
export const fetchCache = 'default-cache' | ||
|
||
// this is ensuring we still update TTL even | ||
// if the cache value didn't change during revalidate | ||
const stableCacheItem = unstable_cache( | ||
async () => { | ||
return 'consistent value' | ||
}, | ||
[], | ||
{ | ||
revalidate: 3, | ||
tags: ['thankyounext'], | ||
} | ||
) | ||
|
||
export default async function Page() { | ||
const data = await fetch('https://example.vercel.sh', { | ||
next: { tags: ['thankyounext'], revalidate: 3 }, | ||
}).then((res) => res.text()) | ||
|
||
const cachedValue = stableCacheItem() | ||
|
||
return ( | ||
<> | ||
<p>hello world</p> | ||
<p id="data">{data}</p> | ||
<p id="cache">{cachedValue}</p> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters