@@ -72,16 +72,17 @@ interface ShardedDOTagCacheOptions {
7272 maxWriteRetries ?: number ;
7373}
7474
75- interface TagCacheDOIdOptions {
75+ interface DOIdOptions {
7676 baseShardId : string ;
7777 numberOfReplicas : number ;
7878 shardType : "soft" | "hard" ;
7979 replicaId ?: number ;
8080}
81- export class TagCacheDOId {
81+
82+ export class DOId {
8283 shardId : string ;
8384 replicaId : number ;
84- constructor ( public options : TagCacheDOIdOptions ) {
85+ constructor ( public options : DOIdOptions ) {
8586 const { baseShardId, shardType, numberOfReplicas, replicaId } = options ;
8687 this . shardId = `tag-${ shardType } ;${ baseShardId } ` ;
8788 this . replicaId = replicaId ?? this . generateRandomNumberBetween ( 1 , numberOfReplicas ) ;
@@ -109,7 +110,7 @@ class ShardedDOTagCache implements NextModeTagCache {
109110 this . maxWriteRetries = opts . maxWriteRetries ?? DEFAULT_WRITE_RETRIES ;
110111 }
111112
112- private getDurableObjectStub ( doId : TagCacheDOId ) {
113+ private getDurableObjectStub ( doId : DOId ) {
113114 const durableObject = getCloudflareContext ( ) . env . NEXT_TAG_CACHE_DO_SHARDED ;
114115 if ( ! durableObject ) throw new IgnorableError ( "No durable object binding for cache revalidation" ) ;
115116
@@ -143,7 +144,7 @@ class ShardedDOTagCache implements NextModeTagCache {
143144 . filter ( ( tag ) => ( isSoft ? tag . startsWith ( SOFT_TAG_PREFIX ) : ! tag . startsWith ( SOFT_TAG_PREFIX ) ) )
144145 . map ( ( tag ) => {
145146 return {
146- doId : new TagCacheDOId ( {
147+ doId : new DOId ( {
147148 baseShardId : generateShardId ( tag , this . opts . baseShardSize , "shard" ) ,
148149 numberOfReplicas : numReplicas ,
149150 shardType,
@@ -173,7 +174,7 @@ class ShardedDOTagCache implements NextModeTagCache {
173174 const tagsByDOId = new Map <
174175 string ,
175176 {
176- doId : TagCacheDOId ;
177+ doId : DOId ;
177178 tags : string [ ] ;
178179 }
179180 > ( ) ;
@@ -262,7 +263,7 @@ class ShardedDOTagCache implements NextModeTagCache {
262263 ) ;
263264 }
264265
265- async performWriteTagsWithRetry ( doId : TagCacheDOId , tags : string [ ] , lastModified : number , retryNumber = 0 ) {
266+ async performWriteTagsWithRetry ( doId : DOId , tags : string [ ] , lastModified : number , retryNumber = 0 ) {
266267 try {
267268 const stub = this . getDurableObjectStub ( doId ) ;
268269 await stub . writeTags ( tags , lastModified ) ;
@@ -292,13 +293,13 @@ class ShardedDOTagCache implements NextModeTagCache {
292293 return this . localCache ;
293294 }
294295
295- async getCacheKey ( doId : TagCacheDOId , tags : string [ ] ) {
296+ async getCacheKey ( doId : DOId , tags : string [ ] ) {
296297 return new Request (
297298 new URL ( `shard/${ doId . shardId } ?tags=${ encodeURIComponent ( tags . join ( ";" ) ) } ` , "http://local.cache" )
298299 ) ;
299300 }
300301
301- async getFromRegionalCache ( doId : TagCacheDOId , tags : string [ ] ) {
302+ async getFromRegionalCache ( doId : DOId , tags : string [ ] ) {
302303 try {
303304 if ( ! this . opts . regionalCache ) return ;
304305 const cache = await this . getCacheInstance ( ) ;
@@ -311,7 +312,7 @@ class ShardedDOTagCache implements NextModeTagCache {
311312 }
312313 }
313314
314- async putToRegionalCache ( doId : TagCacheDOId , tags : string [ ] , hasBeenRevalidated : boolean ) {
315+ async putToRegionalCache ( doId : DOId , tags : string [ ] , hasBeenRevalidated : boolean ) {
315316 if ( ! this . opts . regionalCache ) return ;
316317 const cache = await this . getCacheInstance ( ) ;
317318 if ( ! cache ) return ;
@@ -324,7 +325,7 @@ class ShardedDOTagCache implements NextModeTagCache {
324325 ) ;
325326 }
326327
327- async deleteRegionalCache ( doId : TagCacheDOId , tags : string [ ] ) {
328+ async deleteRegionalCache ( doId : DOId , tags : string [ ] ) {
328329 // We never want to crash because of the cache
329330 try {
330331 if ( ! this . opts . regionalCache ) return ;
0 commit comments