Unverified Commit be717138 authored by Sebastian Markbåge's avatar Sebastian Markbåge Committed by GitHub

Check tag staleness against the timestamp of the entry (#71520)

Not current time. `revalidatedAt` should always be lower than the
current time. Otherwise it's some kind of drift or bug.
parent b15d4818
...@@ -34,9 +34,6 @@ const DefaultCacheHandler: CacheHandler = { ...@@ -34,9 +34,6 @@ const DefaultCacheHandler: CacheHandler = {
async get(cacheKey, softTags) { async get(cacheKey, softTags) {
await pendingSets.get(cacheKey) await pendingSets.get(cacheKey)
if (isTagStale(softTags)) {
return
}
const privateEntry = memoryCache.get(cacheKey) const privateEntry = memoryCache.get(cacheKey)
if (!privateEntry) { if (!privateEntry) {
...@@ -50,11 +47,14 @@ const DefaultCacheHandler: CacheHandler = { ...@@ -50,11 +47,14 @@ const DefaultCacheHandler: CacheHandler = {
) { ) {
// In memory caches should expire after revalidate time because it is unlikely that // 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. // a new entry will be able to be used before it is dropped from the cache.
return return undefined
} }
if (isTagStale(entry.tags || [])) { if (
return isTagStale(entry.tags, entry.timestamp) ||
isTagStale(softTags, entry.timestamp)
) {
return undefined
} }
const [returnStream, newSaved] = entry.value.tee() const [returnStream, newSaved] = entry.value.tee()
entry.value = newSaved entry.value = newSaved
......
...@@ -8,13 +8,13 @@ export const tagsManifest: TagsManifest = { ...@@ -8,13 +8,13 @@ export const tagsManifest: TagsManifest = {
items: {}, items: {},
} }
export const isTagStale = (tags: string[]) => { export const isTagStale = (tags: string[], timestamp: number) => {
for (const tag of tags) { for (const tag of tags) {
const tagEntry = tagsManifest.items[tag] const tagEntry = tagsManifest.items[tag]
if ( if (
typeof tagEntry?.revalidatedAt === 'number' && typeof tagEntry?.revalidatedAt === 'number' &&
// TODO: use performance.now and update file-system-cache? // TODO: use performance.now and update file-system-cache?
tagEntry.revalidatedAt >= Date.now() tagEntry.revalidatedAt >= timestamp
) { ) {
return true return true
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment