@@ -147,27 +147,24 @@ export default class S3Cache {
147
147
148
148
if ( value === undefined ) return null ;
149
149
150
- // For cases where we don't have tags, we need to ensure that we insert at least an entry
151
- // for this specific paths, otherwise we might not be able to invalidate it
150
+ // For cases where we don't have tags, we need to ensure that the soft tags are not being revalidated
151
+ // We only need to check for the path as it should already contain all the tags
152
152
if ( ( tags ?? [ ] ) . length === 0 ) {
153
- // First we check if we have any tags for the given key
154
- const storedTags = await globalThis . tagCache . getByPath ( key ) ;
155
- if ( storedTags . length === 0 ) {
156
- // Then we need to find the path for the given key
157
- const path = softTags ?. find (
158
- ( tag ) =>
159
- tag . startsWith ( "_N_T_/" ) &&
160
- ! tag . endsWith ( "layout" ) &&
161
- ! tag . endsWith ( "page" ) ,
153
+ // Then we need to find the path for the given key
154
+ const path = softTags ?. find (
155
+ ( tag ) =>
156
+ tag . startsWith ( "_N_T_/" ) &&
157
+ ! tag . endsWith ( "layout" ) &&
158
+ ! tag . endsWith ( "page" ) ,
159
+ ) ;
160
+ if ( path ) {
161
+ const pathLastModified = await globalThis . tagCache . getLastModified (
162
+ path . replace ( "_N_T_/" , "" ) ,
163
+ lastModified ,
162
164
) ;
163
- if ( path ) {
164
- // And write the path with the tag
165
- await globalThis . tagCache . writeTags ( [
166
- {
167
- path : key ,
168
- tag : path ,
169
- } ,
170
- ] ) ;
165
+ if ( pathLastModified === - 1 ) {
166
+ // In case the path has been revalidated, we don't want to use the fetch cache
167
+ return null ;
171
168
}
172
169
}
173
170
}
@@ -338,6 +335,9 @@ export default class S3Cache {
338
335
tagsToWrite . map ( ( tag ) => ( {
339
336
path : key ,
340
337
tag : tag ,
338
+ // In case the tags are not there we just need to create them
339
+ // but we don't want them to return from `getLastModified` as they are not stale
340
+ revalidatedAt : 1 ,
341
341
} ) ) ,
342
342
) ;
343
343
}
0 commit comments