@@ -15,6 +15,28 @@ export default {
15
15
16
16
debug ( "composable cache result" , result ) ;
17
17
18
+ // We need to check if the tags associated with this entry has been revalidated
19
+ if (
20
+ globalThis . tagCache . mode === "nextMode" &&
21
+ result . value . tags . length > 0
22
+ ) {
23
+ const hasBeenRevalidated = await globalThis . tagCache . hasBeenRevalidated (
24
+ result . value . tags ,
25
+ result . lastModified ,
26
+ ) ;
27
+ if ( hasBeenRevalidated ) return undefined ;
28
+ } else if (
29
+ globalThis . tagCache . mode === "original" ||
30
+ globalThis . tagCache . mode === undefined
31
+ ) {
32
+ const hasBeenRevalidated =
33
+ ( await globalThis . tagCache . getLastModified (
34
+ cacheKey ,
35
+ result . lastModified ,
36
+ ) ) === - 1 ;
37
+ if ( hasBeenRevalidated ) return undefined ;
38
+ }
39
+
18
40
return {
19
41
...result . value ,
20
42
value : toReadableStream ( result . value . value ) ,
@@ -36,6 +58,15 @@ export default {
36
58
} ,
37
59
"composable" ,
38
60
) ;
61
+ if ( globalThis . tagCache . mode === "original" ) {
62
+ const storedTags = await globalThis . tagCache . getByPath ( cacheKey ) ;
63
+ const tagsToWrite = entry . tags . filter ( ( tag ) => ! storedTags . includes ( tag ) ) ;
64
+ if ( tagsToWrite . length > 0 ) {
65
+ await globalThis . tagCache . writeTags (
66
+ tagsToWrite . map ( ( tag ) => ( { tag, path : cacheKey } ) ) ,
67
+ ) ;
68
+ }
69
+ }
39
70
} ,
40
71
41
72
async refreshTags ( ) {
@@ -46,12 +77,33 @@ export default {
46
77
if ( globalThis . tagCache . mode === "nextMode" ) {
47
78
return globalThis . tagCache . getLastRevalidated ( tags ) ;
48
79
}
49
- //TODO: Not supported for now - I'll need to figure out a way, maybe we'd want to merge both type into one
80
+ // We always return 0 here, original tag cache are handled directly in the get part
81
+ // TODO: We need to test this more, i'm not entirely sure that this is working as expected
50
82
return 0 ;
51
83
} ,
52
84
async expireTags ( ...tags : string [ ] ) {
53
85
if ( globalThis . tagCache . mode === "nextMode" ) {
54
86
return globalThis . tagCache . writeTags ( tags ) ;
55
87
}
88
+ const tagCache = globalThis . tagCache ;
89
+ const revalidatedAt = Date . now ( ) ;
90
+ // For the original mode, we have more work to do here.
91
+ // We need to find all paths linked to to these tags
92
+ const pathsToUpdate = await Promise . all (
93
+ tags . map ( async ( tag ) => {
94
+ const paths = await tagCache . getByTag ( tag ) ;
95
+ return paths . map ( ( path ) => ( {
96
+ path,
97
+ tag,
98
+ revalidatedAt,
99
+ } ) ) ;
100
+ } ) ,
101
+ ) ;
102
+ // We need to deduplicate paths, we use a set for that
103
+ const setToWrite = new Set < { path : string ; tag : string } > ( ) ;
104
+ for ( const entry of pathsToUpdate . flat ( ) ) {
105
+ setToWrite . add ( entry ) ;
106
+ }
107
+ await globalThis . tagCache . writeTags ( Array . from ( setToWrite ) ) ;
56
108
} ,
57
109
} satisfies ComposableCacheHandler ;
0 commit comments