-
Notifications
You must be signed in to change notification settings - Fork 30.5k
app-router: new client-side cache semantics #48383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
feedthejim
merged 33 commits into
canary
from
feedthejim/next-1011-implement-new-caching-heuristics
Apr 21, 2023
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
78fa2f5
initial changes
feedthejim 2391805
cleanup
feedthejim d788576
Merge branch 'canary' into feedthejim/next-1011-implement-new-caching…
feedthejim 9b1c195
use string enums
feedthejim 0e6e717
change comment
feedthejim db0ac92
prune cache entries + create temp cache entries on router.push
feedthejim 6f74db1
Merge branch 'canary' into feedthejim/next-1011-implement-new-caching…
feedthejim 4fe7c81
remove tests
feedthejim 652a7a6
add new methods to the browser interface
feedthejim b09f0bc
add tests
feedthejim 4fd6eed
final implementation
feedthejim d5f99cf
Merge branch 'canary' into feedthejim/next-1011-implement-new-caching…
feedthejim a90421c
disable lint
feedthejim a2a5f84
fix scroll
feedthejim 7989fdd
remove tests
feedthejim bbf6e3d
test out removing the optimistic nav path
feedthejim f74255b
Merge branch 'canary' into feedthejim/next-1011-implement-new-caching…
feedthejim 4334b22
Merge branch 'canary' into feedthejim/next-1011-implement-new-caching…
feedthejim 577ce1f
add a new fresh
feedthejim 84d8bbc
Merge branch 'canary' into feedthejim/next-1011-implement-new-caching…
feedthejim 7c6d769
Merge branch 'canary' into feedthejim/next-1011-implement-new-caching…
feedthejim 65e533d
remove inferred param
feedthejim 6f8705d
prune prefetch cache on prefetch
feedthejim 85c3c15
refactor logic in layout-router
feedthejim 66e66fe
use enums for prefetch kind
feedthejim 4b540ae
navigate refactor
feedthejim 95ef6cf
fix optimisticNav
feedthejim 42d3679
fix build
feedthejim b52dc80
don't write to cache.data
feedthejim 4500047
fix optimistic segment
feedthejim 0c817ee
fix enum usage
feedthejim ebf08f0
Merge branch 'canary' into feedthejim/next-1011-implement-new-caching…
feedthejim afb3f7f
fix flaky test
feedthejim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
40 changes: 40 additions & 0 deletions
40
packages/next/src/client/components/router-reducer/get-prefetch-cache-entry-status.ts
This file contains hidden or 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,40 @@ | ||
| import { PrefetchCacheEntry } from './router-reducer-types' | ||
|
|
||
| const FIVE_MINUTES = 5 * 60 * 1000 | ||
| const THIRTY_SECONDS = 30 * 1000 | ||
|
|
||
| export enum PrefetchCacheEntryStatus { | ||
| fresh = 'fresh', | ||
| reusable = 'reusable', | ||
| expired = 'expired', | ||
| stale = 'stale', | ||
| } | ||
|
|
||
| export function getPrefetchEntryCacheStatus({ | ||
| kind, | ||
| prefetchTime, | ||
| lastUsedTime, | ||
| }: PrefetchCacheEntry): PrefetchCacheEntryStatus { | ||
| // if the cache entry was prefetched or read less than 30s ago, then we want to re-use it | ||
| if (Date.now() < (lastUsedTime ?? prefetchTime) + THIRTY_SECONDS) { | ||
feedthejim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return lastUsedTime | ||
| ? PrefetchCacheEntryStatus.reusable | ||
| : PrefetchCacheEntryStatus.fresh | ||
| } | ||
|
|
||
| // if the cache entry was prefetched less than 5 mins ago, then we want to re-use only the loading state | ||
| if (kind === 'auto') { | ||
| if (Date.now() < prefetchTime + FIVE_MINUTES) { | ||
| return PrefetchCacheEntryStatus.stale | ||
| } | ||
| } | ||
|
|
||
| // if the cache entry was prefetched less than 5 mins ago and was a "full" prefetch, then we want to re-use it "full | ||
| if (kind === 'full') { | ||
| if (Date.now() < prefetchTime + FIVE_MINUTES) { | ||
| return PrefetchCacheEntryStatus.reusable | ||
| } | ||
| } | ||
|
|
||
| return PrefetchCacheEntryStatus.expired | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.