diff --git a/frontend/openchat-agent/src/utils/caching.ts b/frontend/openchat-agent/src/utils/caching.ts index e7158d3e05..84d36519c6 100644 --- a/frontend/openchat-agent/src/utils/caching.ts +++ b/frontend/openchat-agent/src/utils/caching.ts @@ -45,6 +45,7 @@ import { MessageContextMap, MAX_EVENTS, MAX_MESSAGES, + ONE_DAY, updateCreatedUser, } from "openchat-shared"; import type { Principal } from "@dfinity/principal"; @@ -354,7 +355,21 @@ export async function getCachedChats( db: Database, principal: Principal, ): Promise { - return await (await db).get("chats", principal.toString()); + const resolvedDb = await db; + const chats = await resolvedDb.get("chats", principal.toString()); + + if ( + chats !== undefined && + chats.latestUserCanisterUpdates < BigInt(Date.now() - 30 * ONE_DAY) + ) { + // If the cache was last updated more than 30 days ago, clear the cache and return undefined + const storeNames = resolvedDb.objectStoreNames; + for (let i = 0; i < storeNames.length; i++) { + await resolvedDb.clear(storeNames[i]); + } + return undefined; + } + return chats; } export async function setCachedChats(