Skip to content

Commit c01de38

Browse files
add a bunch of logs
1 parent bd97780 commit c01de38

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/cloudflare/src/api/kvCache.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ export const STATUS_DELETED = 1;
1717
class Cache implements IncrementalCache {
1818
readonly name = "cloudflare-kv";
1919

20+
constructor() {
21+
console.log(`========> cloudflare-kv Cache INIT`);
22+
}
23+
2024
async get<IsFetch extends boolean = false>(
2125
key: string,
2226
isFetch?: IsFetch
2327
): Promise<WithLastModified<CacheValue<IsFetch>>> {
28+
console.log(`========> KVCache.get (${key})`);
29+
2430
const cfEnv = getCloudflareContext().env;
2531
const kv = cfEnv.NEXT_CACHE_WORKERS_KV;
2632
const assets = cfEnv.ASSETS;
@@ -39,15 +45,18 @@ class Cache implements IncrementalCache {
3945
} | null = null;
4046

4147
if (kv) {
48+
console.log(` from KV`);
4249
this.debug(`- From KV`);
4350
const kvKey = this.getKVKey(key, isFetch);
4451
entry = await kv.get(kvKey, "json");
52+
console.log(` does entry from KV exist? ${!!entry}`);
4553
if (entry?.status === STATUS_DELETED) {
4654
return {};
4755
}
4856
}
4957

5058
if (!entry && assets) {
59+
console.log(` from assets`);
5160
this.debug(`- From Assets`);
5261
const url = this.getAssetUrl(key, isFetch);
5362
const response = await assets.fetch(url);
@@ -61,10 +70,12 @@ class Cache implements IncrementalCache {
6170
lastModified: (globalThis as { __BUILD_TIMESTAMP_MS__?: number }).__BUILD_TIMESTAMP_MS__,
6271
};
6372
}
73+
console.log(` does entry from assets exist? ${!!entry}`);
6474
}
6575
this.debug(entry ? `-> hit` : `-> miss`);
6676
return { value: entry?.value, lastModified: entry?.lastModified };
6777
} catch {
78+
console.log(` ERROR! FAILED TO GET Cache`);
6879
throw new RecoverableError(`Failed to get cache [${key}]`);
6980
}
7081
}
@@ -74,13 +85,16 @@ class Cache implements IncrementalCache {
7485
value: CacheValue<IsFetch>,
7586
isFetch?: IsFetch
7687
): Promise<void> {
88+
console.log(`========> KVCache.set (${key})`);
89+
7790
const kv = getCloudflareContext().env.NEXT_CACHE_WORKERS_KV;
7891

7992
if (!kv) {
93+
console.log(` NO KV!`);
8094
throw new IgnorableError(`No KVNamespace`);
8195
}
8296

83-
this.debug(`Set ${key}`);
97+
console.log(` from KV`);
8498

8599
try {
86100
const kvKey = this.getKVKey(key, isFetch);
@@ -97,6 +111,7 @@ class Cache implements IncrementalCache {
97111
})
98112
);
99113
} catch {
114+
console.log(` ERROR! FAILED TO SET Cache`);
100115
throw new RecoverableError(`Failed to set cache [${key}]`);
101116
}
102117
}

0 commit comments

Comments
 (0)