Skip to content

Commit 36aca92

Browse files
add a bunch of logs
1 parent bd97780 commit 36aca92

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

packages/cloudflare/src/api/kvCache.ts

Lines changed: 17 additions & 2 deletions
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.error(`========> 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.error(`========> 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.error(` from KV`);
4249
this.debug(`- From KV`);
4350
const kvKey = this.getKVKey(key, isFetch);
4451
entry = await kv.get(kvKey, "json");
52+
console.error(` does entry from KV exist? ${!!entry}`);
4553
if (entry?.status === STATUS_DELETED) {
4654
return {};
4755
}
4856
}
4957

5058
if (!entry && assets) {
59+
console.error(` 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.error(` 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.error(` 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.error(`========> KVCache.set (${key})`);
89+
7790
const kv = getCloudflareContext().env.NEXT_CACHE_WORKERS_KV;
7891

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

83-
this.debug(`Set ${key}`);
97+
console.error(` 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.error(` ERROR! FAILED TO SET Cache`);
100115
throw new RecoverableError(`Failed to set cache [${key}]`);
101116
}
102117
}
@@ -131,7 +146,7 @@ class Cache implements IncrementalCache {
131146

132147
protected debug(...args: unknown[]) {
133148
if (process.env.NEXT_PRIVATE_DEBUG_CACHE) {
134-
console.log(`[Cache ${this.name}] `, ...args);
149+
console.error(`[Cache ${this.name}] `, ...args);
135150
}
136151
}
137152

0 commit comments

Comments
 (0)