@@ -294,34 +294,36 @@ class ShardedDOTagCache implements NextModeTagCache {
294
294
return this . localCache ;
295
295
}
296
296
297
- async getCacheKey ( doId : DOId , tags : string [ ] ) {
298
- return new Request (
299
- new URL ( `shard/${ doId . shardId } ?tags=${ encodeURIComponent ( tags . join ( ";" ) ) } ` , "http://local.cache" )
300
- ) ;
297
+ getCacheUrlKey ( doId : DOId , tags : string [ ] ) : string {
298
+ return `http://local.cache/shard/${ doId . shardId } ?tags=${ encodeURIComponent ( tags . join ( ";" ) ) } ` ;
301
299
}
302
300
303
301
async getFromRegionalCache ( doId : DOId , tags : string [ ] ) {
304
302
try {
305
303
if ( ! this . opts . regionalCache ) return ;
306
304
const cache = await this . getCacheInstance ( ) ;
307
305
if ( ! cache ) return ;
308
- const key = await this . getCacheKey ( doId , tags ) ;
309
- return cache . match ( key ) ;
306
+ return cache . match ( this . getCacheUrlKey ( doId , tags ) ) ;
310
307
} catch ( e ) {
311
308
error ( "Error while fetching from regional cache" , e ) ;
312
- return ;
313
309
}
314
310
}
315
311
316
312
async putToRegionalCache ( doId : DOId , tags : string [ ] , hasBeenRevalidated : boolean ) {
317
313
if ( ! this . opts . regionalCache ) return ;
318
314
const cache = await this . getCacheInstance ( ) ;
319
315
if ( ! cache ) return ;
320
- const key = await this . getCacheKey ( doId , tags ) ;
321
316
await cache . put (
322
- key ,
317
+ this . getCacheUrlKey ( doId , tags ) ,
323
318
new Response ( `${ hasBeenRevalidated } ` , {
324
- headers : { "cache-control" : `max-age=${ this . opts . regionalCacheTtlSec ?? 5 } ` } ,
319
+ headers : {
320
+ "cache-control" : `max-age=${ this . opts . regionalCacheTtlSec ?? 5 } ` ,
321
+ ...( tags . length > 0
322
+ ? {
323
+ "cache-tag" : tags . join ( "," ) ,
324
+ }
325
+ : { } ) ,
326
+ } ,
325
327
} )
326
328
) ;
327
329
}
@@ -332,8 +334,7 @@ class ShardedDOTagCache implements NextModeTagCache {
332
334
if ( ! this . opts . regionalCache ) return ;
333
335
const cache = await this . getCacheInstance ( ) ;
334
336
if ( ! cache ) return ;
335
- const key = await this . getCacheKey ( doId , tags ) ;
336
- await cache . delete ( key ) ;
337
+ await cache . delete ( this . getCacheUrlKey ( doId , tags ) ) ;
337
338
} catch ( e ) {
338
339
debugCache ( "Error while deleting from regional cache" , e ) ;
339
340
}
0 commit comments