Cache expiration behavior does not match documented expectations.
The issue involves unexpected behavior in the `cacheLife` `expire` functionality where stale values are returned instead of dynamically fetching new data after the specified expiration time. The problem is reproducible and affects dynamic routes and cache components. The fix requires understanding cache mechanisms and dynamic fetching in Next.js.
https://codesandbox.io/p/devbox/next-cache-life-expire-issue-c6wdvt
npm run build
npm start
This project is using the new canary dynamicIO, use cache and cacheLife functionality.
The documentation for cacheLife expire says:
Maximum duration for which a value can remain stale before switching to dynamic fetching
The following is specified in the sample project:
cacheLife({ stale: 60, revalidate: 3 * 60, expire: 5 * 60 });
Therefore, when refreshing the page after waiting 5 minutes, I expect it to switch to dynamic fetching and return the current time. This is the functionality I want and expect. Instead, the old stale/expired value is being returned.
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023
Available memory (MB): 4242
Available CPU cores: 2
Binaries:
Node: 20.9.0
npm: 9.8.1
Yarn: 1.22.19
pnpm: 8.10.2
Relevant Packages:
next: 15.3.1-canary.11 // Latest available version is detected (15.3.1-canary.11).
eslint-config-next: N/A
react: 19.1.0
react-dom: 19.1.0
typescript: 5.3.3
Next.js Config:
output: N/A
dynamicIO, Dynamic Routes, Use Cache
next start (local)
BTW, not being able to specify an expire time less than 5 minutes is really annoying and makes issues like this hard to debug!
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!