ChatDiffCode Review
> cache order lookups in Redis for 60 s
● Reading src/orders.ts
● Writing src/cache.ts (38 lines)
● Updating getOrder() to read through the cache
● Tests pass: 42 passed, 0 failed
claude · opus · ▰▰▰▱▱ 31%
src/orders.ts
export async function getOrder(id: string) {
- return db.orders.find(id);
+ return cached(`order:${id}`, 60, () => db.orders.find(id));
}
src/cache.ts
+ export async function cached<T>(key: string, ttl: number, load: () => Promise<T>) {
+ const hit = await redis.get(key);
+ if (hit) return JSON.parse(hit) as T;
Committed 2 files to main