diff --git a/app/pages/page.tsx b/app/pages/page.tsx index 5e0f3ac..a886e6e 100644 --- a/app/pages/page.tsx +++ b/app/pages/page.tsx @@ -402,11 +402,15 @@ export default function CarnetPage() { if (!skipCache) { const cachedNotes = notesCache.get(cacheKey); if (cachedNotes) { - console.log(`[fetchNotes] Using cached notes for ${folderLowercase} folder`); + console.log(`[fetchNotes] Using cached notes for ${folderLowercase} folder (${cachedNotes.length} notes)`); setNotes(cachedNotes); setIsLoadingNotes(false); return; + } else { + console.log(`[fetchNotes] No cache found for ${folderLowercase} folder, fetching from API`); } + } else { + console.log(`[fetchNotes] Skipping cache for ${folderLowercase} folder (skipCache=true)`); } // Fetch from API @@ -440,12 +444,14 @@ export default function CarnetPage() { ); console.log(`[fetchNotes] Mapped ${uniqueNotes.length} unique notes from ${folderLowercase} folder (${mappedNotes.length} total before deduplication)`); + console.log(`[fetchNotes] Note titles:`, uniqueNotes.map(n => n.title)); // Update state setNotes(uniqueNotes); // Update cache notesCache.set(cacheKey, uniqueNotes); + console.log(`[fetchNotes] Cache updated for ${folderLowercase} folder with ${uniqueNotes.length} notes`); } else { const errorData = await response.json().catch(() => ({})); console.error('[fetchNotes] Error fetching notes:', errorData.message || response.statusText); diff --git a/lib/cache-utils.ts b/lib/cache-utils.ts index da3df82..af0a15b 100644 --- a/lib/cache-utils.ts +++ b/lib/cache-utils.ts @@ -210,12 +210,21 @@ export function invalidateFolderCache(userId: string, folder: string): void { const cacheKey = `${userId}-${folderLowercase}`; // Clear notes list cache + const hadCache = notesCache.get(cacheKey) !== null; notesCache.remove(cacheKey); // Clear all note content caches for this folder (pattern match) noteContentCache.clearPattern(`user-${userId}/${folderLowercase}/`); - console.log(`Cache invalidated for folder: ${folderLowercase}`); + console.log(`[invalidateFolderCache] Cache invalidated for folder: ${folderLowercase} (had cache: ${hadCache})`); + + // Double-check that cache is cleared + const stillCached = notesCache.get(cacheKey); + if (stillCached) { + console.warn(`[invalidateFolderCache] WARNING: Cache still exists after removal for ${cacheKey}`); + // Force clear all matching keys + notesCache.clearPattern(cacheKey); + } } /**