feat: enhance README and improve product data handling in cache, llm, reader, and writer modules
This commit is contained in:
21
src/cache.ts
21
src/cache.ts
@@ -12,11 +12,20 @@ export async function connectCache(): Promise<void> {
|
||||
maxRetriesPerRequest: 1,
|
||||
connectTimeout: 3000,
|
||||
lazyConnect: true,
|
||||
retryStrategy: () => null,
|
||||
reconnectOnError: () => false,
|
||||
});
|
||||
// Swallow connection-level errors after we intentionally disable cache.
|
||||
redis.on("error", () => {
|
||||
// no-op
|
||||
});
|
||||
await redis.connect();
|
||||
console.log("Redis connected");
|
||||
} catch (err) {
|
||||
console.warn(`Redis unavailable, running without cache: ${err}`);
|
||||
if (redis) {
|
||||
redis.disconnect();
|
||||
}
|
||||
redis = null;
|
||||
disabled = true;
|
||||
}
|
||||
@@ -32,10 +41,18 @@ export async function getCache(asin: string): Promise<EnrichedProduct | null> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function setCache(asin: string, data: EnrichedProduct): Promise<void> {
|
||||
export async function setCache(
|
||||
asin: string,
|
||||
data: EnrichedProduct,
|
||||
): Promise<void> {
|
||||
if (!redis) return;
|
||||
try {
|
||||
await redis.set(`asin:${asin}`, JSON.stringify(data), "EX", config.cacheTtl);
|
||||
await redis.set(
|
||||
`asin:${asin}`,
|
||||
JSON.stringify(data),
|
||||
"EX",
|
||||
config.cacheTtl,
|
||||
);
|
||||
} catch {
|
||||
// Non-critical, continue without caching
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user