-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland app-router: new client-side cache semantics (#48685)
- Loading branch information
Showing
27 changed files
with
951 additions
and
271 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
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
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
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
40 changes: 40 additions & 0 deletions
40
packages/next/src/client/components/router-reducer/get-prefetch-cache-entry-status.ts
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,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) { | ||
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 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
Oops, something went wrong.