@@ -294,34 +294,36 @@ class ShardedDOTagCache implements NextModeTagCache {
294294 return this . localCache ;
295295 }
296296
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 ( ";" ) ) } ` ;
301299 }
302300
303301 async getFromRegionalCache ( doId : DOId , tags : string [ ] ) {
304302 try {
305303 if ( ! this . opts . regionalCache ) return ;
306304 const cache = await this . getCacheInstance ( ) ;
307305 if ( ! cache ) return ;
308- const key = await this . getCacheKey ( doId , tags ) ;
309- return cache . match ( key ) ;
306+ return cache . match ( this . getCacheUrlKey ( doId , tags ) ) ;
310307 } catch ( e ) {
311308 error ( "Error while fetching from regional cache" , e ) ;
312- return ;
313309 }
314310 }
315311
316312 async putToRegionalCache ( doId : DOId , tags : string [ ] , hasBeenRevalidated : boolean ) {
317313 if ( ! this . opts . regionalCache ) return ;
318314 const cache = await this . getCacheInstance ( ) ;
319315 if ( ! cache ) return ;
320- const key = await this . getCacheKey ( doId , tags ) ;
321316 await cache . put (
322- key ,
317+ this . getCacheUrlKey ( doId , tags ) ,
323318 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+ } ,
325327 } )
326328 ) ;
327329 }
@@ -332,8 +334,7 @@ class ShardedDOTagCache implements NextModeTagCache {
332334 if ( ! this . opts . regionalCache ) return ;
333335 const cache = await this . getCacheInstance ( ) ;
334336 if ( ! cache ) return ;
335- const key = await this . getCacheKey ( doId , tags ) ;
336- await cache . delete ( key ) ;
337+ await cache . delete ( this . getCacheUrlKey ( doId , tags ) ) ;
337338 } catch ( e ) {
338339 debugCache ( "Error while deleting from regional cache" , e ) ;
339340 }
0 commit comments