@@ -25,6 +25,17 @@ export class KVNextModeTagCache implements NextModeTagCache {
25
25
readonly name = NAME ;
26
26
27
27
async getLastRevalidated ( tags : string [ ] ) : Promise < number > {
28
+ const timeMs = await this . #getLastRevalidated( tags ) ;
29
+ debugCache ( "KVNextModeTagCache" , `getLastRevalidated tags=${ tags } -> time=${ timeMs } ` ) ;
30
+ return timeMs ;
31
+ }
32
+
33
+ /**
34
+ * Implementation of `getLastRevalidated`.
35
+ *
36
+ * This implementation is separated so that `hasBeenRevalidated` do not include logs from `getLastRevalidated`.
37
+ */
38
+ async #getLastRevalidated( tags : string [ ] ) : Promise < number > {
28
39
const kv = this . getKv ( ) ;
29
40
if ( ! kv || tags . length === 0 ) {
30
41
return 0 ;
@@ -36,10 +47,7 @@ export class KVNextModeTagCache implements NextModeTagCache {
36
47
const result : Map < string , number | null > = await kv . get ( keys , { type : "json" } ) ;
37
48
38
49
const revalidations = [ ...result . values ( ) ] . filter ( ( v ) => v != null ) ;
39
-
40
- const timeMs = revalidations . length === 0 ? 0 : Math . max ( ...revalidations ) ;
41
- debugCache ( "KVNextModeTagCache" , `getLastRevalidated tags=${ tags } -> time=${ timeMs } ` ) ;
42
- return timeMs ;
50
+ return revalidations . length === 0 ? 0 : Math . max ( ...revalidations ) ;
43
51
} catch ( e ) {
44
52
// By default we don't want to crash here, so we return false
45
53
// We still log the error though so we can debug it
@@ -49,7 +57,7 @@ export class KVNextModeTagCache implements NextModeTagCache {
49
57
}
50
58
51
59
async hasBeenRevalidated ( tags : string [ ] , lastModified ?: number ) : Promise < boolean > {
52
- const revalidated = ( await this . getLastRevalidated ( tags ) ) > ( lastModified ?? Date . now ( ) ) ;
60
+ const revalidated = ( await this . # getLastRevalidated( tags ) ) > ( lastModified ?? Date . now ( ) ) ;
53
61
debugCache (
54
62
"KVNextModeTagCache" ,
55
63
`hasBeenRevalidated tags=${ tags } lastModified=${ lastModified } -> ${ revalidated } `
0 commit comments