Skip to content
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

Check tag staleness against the timestamp of the entry #71520

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/next/src/server/lib/cache-handlers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const DefaultCacheHandler: CacheHandler = {
async get(cacheKey, softTags) {
await pendingSets.get(cacheKey)

if (isTagStale(softTags)) {
return
}
const privateEntry = memoryCache.get(cacheKey)

if (!privateEntry) {
Expand All @@ -50,11 +47,14 @@ const DefaultCacheHandler: CacheHandler = {
) {
// In memory caches should expire after revalidate time because it is unlikely that
// a new entry will be able to be used before it is dropped from the cache.
return
return undefined
}

if (isTagStale(entry.tags || [])) {
return
if (
isTagStale(entry.tags, entry.timestamp) ||
isTagStale(softTags, entry.timestamp)
) {
return undefined
}
const [returnStream, newSaved] = entry.value.tee()
entry.value = newSaved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export const tagsManifest: TagsManifest = {
items: {},
}

export const isTagStale = (tags: string[]) => {
export const isTagStale = (tags: string[], timestamp: number) => {
for (const tag of tags) {
const tagEntry = tagsManifest.items[tag]
if (
typeof tagEntry?.revalidatedAt === 'number' &&
// TODO: use performance.now and update file-system-cache?
tagEntry.revalidatedAt >= Date.now()
tagEntry.revalidatedAt >= timestamp
) {
return true
}
Expand Down
Loading