Skip to content

Commit 32b550d

Browse files
committed
feat: initial implementation
1 parent 9a4dda7 commit 32b550d

File tree

3 files changed

+314
-57
lines changed

3 files changed

+314
-57
lines changed

src/run/handlers/server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { setupWaitUntil } from './wait-until.cjs'
2525
setFetchBeforeNextPatchedIt(globalThis.fetch)
2626
// configure some globals that Next.js make use of before we start importing any Next.js code
2727
// as some globals are consumed at import time
28+
// TODO: only call this if Next.js version is using CacheHandlerV2 as we don't have V1 compatible implementation
2829
configureUseCacheHandlers()
2930
setupWaitUntil()
3031

src/run/handlers/tags-handler.cts

+21
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ async function lastTagRevalidationTimestamp(
2525
return tagManifest.revalidatedAt
2626
}
2727

28+
/**
29+
* Get the most recent revalidation timestamp for a list of tags
30+
*/
31+
export async function getMostRecentTagRevalidationTimestamp(tags: string[]) {
32+
if (tags.length === 0) {
33+
return 0
34+
}
35+
36+
const cacheStore = getMemoizedKeyValueStoreBackedByRegionalBlobStore({ consistency: 'strong' })
37+
38+
const timestampsOrNulls = await Promise.all(
39+
tags.map((tag) => lastTagRevalidationTimestamp(tag, cacheStore)),
40+
)
41+
42+
const timestamps = timestampsOrNulls.filter((timestamp) => timestamp !== null)
43+
if (timestamps.length === 0) {
44+
return 0
45+
}
46+
return Math.max(...timestamps)
47+
}
48+
2849
/**
2950
* Check if any of the tags were invalidated since the given timestamp
3051
*/

0 commit comments

Comments
 (0)