@@ -6,6 +6,7 @@ import type {
6
6
import type { CacheKey } from "types/overrides" ;
7
7
import {
8
8
createCacheKey ,
9
+ createTagKey ,
9
10
getTagsFromValue ,
10
11
hasBeenRevalidated ,
11
12
writeTags ,
@@ -71,7 +72,7 @@ export default class Cache {
71
72
const _tags = [ ...( tags ?? [ ] ) , ...( softTags ?? [ ] ) ] ;
72
73
const _lastModified = cachedEntry . lastModified ?? Date . now ( ) ;
73
74
const _hasBeenRevalidated = await hasBeenRevalidated (
74
- baseKey ,
75
+ key ,
75
76
_tags ,
76
77
cachedEntry ,
77
78
) ;
@@ -90,7 +91,7 @@ export default class Cache {
90
91
) ;
91
92
if ( path ) {
92
93
const hasPathBeenUpdated = await hasBeenRevalidated (
93
- path . replace ( "_N_T_/" , "" ) ,
94
+ createCacheKey ( { key : path . replace ( "_N_T_/" , "" ) , type : "cache" } ) ,
94
95
[ ] ,
95
96
cachedEntry ,
96
97
) ;
@@ -132,7 +133,7 @@ export default class Cache {
132
133
const tags = getTagsFromValue ( cacheData ) ;
133
134
const _lastModified = cachedEntry . lastModified ?? Date . now ( ) ;
134
135
const _hasBeenRevalidated = await hasBeenRevalidated (
135
- baseKey ,
136
+ key ,
136
137
tags ,
137
138
cachedEntry ,
138
139
) ;
@@ -323,7 +324,7 @@ export default class Cache {
323
324
324
325
try {
325
326
if ( globalThis . tagCache . mode === "nextMode" ) {
326
- const paths = ( await globalThis . tagCache . getPathsByTags ?.( _tags ) ) ?? [ ] ;
327
+ const paths = ( await globalThis . tagCache . getPathsByTags ?.( _tags . map ( createTagKey ) ) ) ?? [ ] ;
327
328
328
329
await writeTags ( _tags ) ;
329
330
if ( paths . length > 0 ) {
@@ -349,7 +350,7 @@ export default class Cache {
349
350
for ( const tag of _tags ) {
350
351
debug ( "revalidateTag" , tag ) ;
351
352
// Find all keys with the given tag
352
- const paths = await globalThis . tagCache . getByTag ( tag ) ;
353
+ const paths = await globalThis . tagCache . getByTag ( createTagKey ( tag ) ) ;
353
354
debug ( "Items" , paths ) ;
354
355
const toInsert = paths . map ( ( path ) => ( {
355
356
path,
@@ -360,11 +361,11 @@ export default class Cache {
360
361
if ( tag . startsWith ( "_N_T_/" ) ) {
361
362
for ( const path of paths ) {
362
363
// We need to find all hard tags for a given path
363
- const _tags = await globalThis . tagCache . getByPath ( path ) ;
364
+ const _tags = await globalThis . tagCache . getByPath ( createTagKey ( path ) ) ;
364
365
const hardTags = _tags . filter ( ( t ) => ! t . startsWith ( "_N_T_/" ) ) ;
365
366
// For every hard tag, we need to find all paths and revalidate them
366
367
for ( const hardTag of hardTags ) {
367
- const _paths = await globalThis . tagCache . getByTag ( hardTag ) ;
368
+ const _paths = await globalThis . tagCache . getByTag ( createTagKey ( hardTag ) ) ;
368
369
debug ( { hardTag, _paths } ) ;
369
370
toInsert . push (
370
371
..._paths . map ( ( path ) => ( {
@@ -377,7 +378,10 @@ export default class Cache {
377
378
}
378
379
379
380
// Update all keys with the given tag with revalidatedAt set to now
380
- await writeTags ( toInsert ) ;
381
+ await writeTags ( toInsert . map ( ( t ) => ( {
382
+ path : createTagKey ( t . path ) ,
383
+ tag : createTagKey ( t . tag ) ,
384
+ } ) ) ) ;
381
385
382
386
// We can now invalidate all paths in the CDN
383
387
// This only applies to `revalidateTag`, not to `res.revalidate()`
@@ -438,13 +442,13 @@ export default class Cache {
438
442
439
443
// Get all tags stored in dynamodb for the given key
440
444
// If any of the derived tags are not stored in dynamodb for the given key, write them
441
- const storedTags = await globalThis . tagCache . getByPath ( key ) ;
445
+ const storedTags = await globalThis . tagCache . getByPath ( createTagKey ( key ) ) ;
442
446
const tagsToWrite = derivedTags . filter ( ( tag ) => ! storedTags . includes ( tag ) ) ;
443
447
if ( tagsToWrite . length > 0 ) {
444
448
await writeTags (
445
449
tagsToWrite . map ( ( tag ) => ( {
446
- path : key ,
447
- tag : tag ,
450
+ path : createTagKey ( key ) ,
451
+ tag : createTagKey ( tag ) ,
448
452
// In case the tags are not there we just need to create them
449
453
// but we don't want them to return from `getLastModified` as they are not stale
450
454
revalidatedAt : 1 ,
0 commit comments