Skip to content

Commit 9a65ebd

Browse files
committed
fixup: TagCacheDOId -> DOId
1 parent be8d5b9 commit 9a65ebd

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

packages/cloudflare/src/api/overrides/tag-cache/do-sharded-tag-cache.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22

3-
import shardedDOTagCache, { TagCacheDOId } from "./do-sharded-tag-cache";
3+
import shardedDOTagCache, { DOId } from "./do-sharded-tag-cache";
44

55
const hasBeenRevalidatedMock = vi.fn();
66
const writeTagsMock = vi.fn();
@@ -279,7 +279,7 @@ describe("DOShardedTagCache", () => {
279279
describe("getFromRegionalCache", () => {
280280
it("should return undefined if regional cache is disabled", async () => {
281281
const cache = shardedDOTagCache();
282-
const doId = new TagCacheDOId({
282+
const doId = new DOId({
283283
baseShardId: "shard-1",
284284
numberOfReplicas: 1,
285285
shardType: "hard",
@@ -295,7 +295,7 @@ describe("DOShardedTagCache", () => {
295295
}),
296296
};
297297
const cache = shardedDOTagCache({ baseShardSize: 4, regionalCache: true });
298-
const doId = new TagCacheDOId({
298+
const doId = new DOId({
299299
baseShardId: "shard-1",
300300
numberOfReplicas: 1,
301301
shardType: "hard",
@@ -309,11 +309,11 @@ describe("DOShardedTagCache", () => {
309309
describe("getCacheKey", () => {
310310
it("should return the cache key without the random part", async () => {
311311
const cache = shardedDOTagCache();
312-
const doId1 = new TagCacheDOId({ baseShardId: "shard-0", numberOfReplicas: 1, shardType: "hard" });
312+
const doId1 = new DOId({ baseShardId: "shard-0", numberOfReplicas: 1, shardType: "hard" });
313313
const reqKey = await cache.getCacheKey(doId1, ["_N_T_/tag1"]);
314314
expect(reqKey.url).toBe("http://local.cache/shard/tag-hard;shard-0?tags=_N_T_%2Ftag1");
315315

316-
const doId2 = new TagCacheDOId({
316+
const doId2 = new DOId({
317317
baseShardId: "shard-1",
318318
numberOfReplicas: 1,
319319
shardType: "hard",
@@ -332,7 +332,7 @@ describe("DOShardedTagCache", () => {
332332
throw new Error("error");
333333
});
334334
const spiedFn = vi.spyOn(cache, "performWriteTagsWithRetry");
335-
const doId = new TagCacheDOId({
335+
const doId = new DOId({
336336
baseShardId: "shard-1",
337337
numberOfReplicas: 1,
338338
shardType: "hard",
@@ -355,7 +355,7 @@ describe("DOShardedTagCache", () => {
355355
});
356356
const spiedFn = vi.spyOn(cache, "performWriteTagsWithRetry");
357357
await cache.performWriteTagsWithRetry(
358-
new TagCacheDOId({ baseShardId: "shard-1", numberOfReplicas: 1, shardType: "hard" }),
358+
new DOId({ baseShardId: "shard-1", numberOfReplicas: 1, shardType: "hard" }),
359359
["tag1"],
360360
Date.now(),
361361
3

packages/cloudflare/src/api/overrides/tag-cache/do-sharded-tag-cache.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)