@@ -25,6 +25,17 @@ export class KVNextModeTagCache implements NextModeTagCache {
2525 readonly name = NAME ;
2626
2727 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 > {
2839 const kv = this . getKv ( ) ;
2940 if ( ! kv || tags . length === 0 ) {
3041 return 0 ;
@@ -36,10 +47,7 @@ export class KVNextModeTagCache implements NextModeTagCache {
3647 const result : Map < string , number | null > = await kv . get ( keys , { type : "json" } ) ;
3748
3849 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 ) ;
4351 } catch ( e ) {
4452 // By default we don't want to crash here, so we return false
4553 // We still log the error though so we can debug it
@@ -49,7 +57,7 @@ export class KVNextModeTagCache implements NextModeTagCache {
4957 }
5058
5159 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 ( ) ) ;
5361 debugCache (
5462 "KVNextModeTagCache" ,
5563 `hasBeenRevalidated tags=${ tags } lastModified=${ lastModified } -> ${ revalidated } `
0 commit comments