Skip to content

Commit cf0731d

Browse files
committed
fix(cache): DistributedCache.update() now writes to Redis on cold L1 instances
1 parent aed644b commit cf0731d

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

lib/cache.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,10 @@ export class DistributedCache<T> {
340340
}
341341

342342
async update(key: string, value: T): Promise<boolean> {
343-
const updated = this.localCache.update(key, value);
344-
if (!updated) return false;
343+
this.localCache.update(key, value);
345344

346345
if (!this.useRedis) {
347-
return true;
346+
return this.localCache.has(key);
348347
}
349348

350349
try {
@@ -354,16 +353,17 @@ export class DistributedCache<T> {
354353
Authorization: `Bearer ${this.redisToken}`,
355354
'Content-Type': 'application/json',
356355
},
357-
body: JSON.stringify(['SET', key, JSON.stringify(value), 'KEEPTTL']),
356+
body: JSON.stringify(['SET', key, JSON.stringify(value), 'KEEPTTL', 'XX']),
358357
});
359358

360359
if (!res.ok) {
361360
throw new Error(`Redis HTTP error: ${res.status}`);
362361
}
363-
return true;
362+
const data = await res.json();
363+
return data.result === 'OK';
364364
} catch (err) {
365365
console.error(`[DistributedCache] UPDATE failed for key "${key}":`, err);
366-
return true;
366+
return false;
367367
}
368368
}
369369

0 commit comments

Comments
 (0)