Improve invoice verification cache reliability and add expiration handling

Fix database storage to correctly check cache expiration and delete expired entries, preventing stale data from being served. Added logs for cache hits, misses, and expirations.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce/6kmwY2j
This commit is contained in:
michaelschal committed 2025-08-17 16:34:37 +00:00
1 parent 971bda0012
commit 4ff83da545
4 files changed
+233 -2

No files matched your search

+27 -1
View File
@@ -1298,7 +1298,33 @@ export class DatabaseStorage implements IStorage {
.select()
.from(invoiceVerificationCache)
.where(eq(invoiceVerificationCache.cacheKey, cacheKey));
return cache;
// ✅ Vérification d'expiration ajoutée pour production
if (cache) {
const now = new Date();
const expiresAt = new Date(cache.expiresAt);
if (now < expiresAt) {
console.log('✅ [DATABASE-CACHE] Cache hit pour:', {
cacheKey,
expires: cache.expiresAt,
hoursRemaining: Math.round((expiresAt.getTime() - now.getTime()) / (1000 * 60 * 60))
});
return cache; // Cache valide
} else {
console.log('⏰ [DATABASE-CACHE] Cache expiré, suppression:', {
cacheKey,
expiredAt: cache.expiresAt
});
// Supprimer le cache expiré
await db.delete(invoiceVerificationCache)
.where(eq(invoiceVerificationCache.cacheKey, cacheKey));
return undefined; // Cache expiré
}
}
console.log('❌ [DATABASE-CACHE] Cache miss pour:', { cacheKey });
return undefined; // Pas de cache
}
async createInvoiceVerificationCache(cacheData: InsertInvoiceVerificationCache): Promise<InvoiceVerificationCache> {