Skip to content

Commit

Permalink
Check tag staleness against the timestamp of the entry (#71520)
Browse files Browse the repository at this point in the history
Not current time. `revalidatedAt` should always be lower than the
current time. Otherwise it's some kind of drift or bug.
  • Loading branch information
sebmarkbage authored Oct 19, 2024
1 parent b15d481 commit be71713
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit be71713

Please sign in to comment.