Skip to content

Commit 8f0a2d4

Browse files
committed
add type for 'durations' with jsdoc description for 'expire' property
1 parent 37c3e8e commit 8f0a2d4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/run/handlers/cache.cts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
isAnyTagStaleOrExpired,
3030
markTagsAsStaleAndPurgeEdgeCache,
3131
purgeEdgeCache,
32+
type RevalidateTagDurations,
3233
type TagStaleOrExpiredStatus,
3334
} from './tags-handler.cjs'
3435
import { getTracer, recordWarning } from './tracer.cjs'
@@ -489,7 +490,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
489490
})
490491
}
491492

492-
async revalidateTag(tagOrTags: string | string[], durations?: { expire?: number }) {
493+
async revalidateTag(tagOrTags: string | string[], durations?: RevalidateTagDurations) {
493494
return markTagsAsStaleAndPurgeEdgeCache(tagOrTags, durations)
494495
}
495496

src/run/handlers/tags-handler.cts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,18 @@ export function purgeEdgeCache(tagOrTags: string | string[]): Promise<void> {
167167
})
168168
}
169169

170+
// shape of this type comes from Next.js https://github.com/vercel/next.js/blob/fffa2831b61fa74852736eeaad2f17fbdd553bce/packages/next/src/server/lib/incremental-cache/index.ts#L78
171+
// and we use it internally
172+
export type RevalidateTagDurations = {
173+
/**
174+
* Number of seconds after which tagged cache entries should no longer serve stale content.
175+
*/
176+
expire?: number
177+
}
178+
170179
async function doRevalidateTagAndPurgeEdgeCache(
171180
tags: string[],
172-
durations?: { expire?: number },
181+
durations?: RevalidateTagDurations,
173182
): Promise<void> {
174183
getLogger().withFields({ tags, durations }).debug('doRevalidateTagAndPurgeEdgeCache')
175184

@@ -201,7 +210,7 @@ async function doRevalidateTagAndPurgeEdgeCache(
201210

202211
export function markTagsAsStaleAndPurgeEdgeCache(
203212
tagOrTags: string | string[],
204-
durations?: { expire?: number },
213+
durations?: RevalidateTagDurations,
205214
) {
206215
const tags = getCacheTagsFromTagOrTags(tagOrTags)
207216

0 commit comments

Comments
 (0)