diff --git a/xmcl-runtime/lib/services/CurseForgeService.ts b/xmcl-runtime/lib/services/CurseForgeService.ts index c76e82da8..8b2f51899 100644 --- a/xmcl-runtime/lib/services/CurseForgeService.ts +++ b/xmcl-runtime/lib/services/CurseForgeService.ts @@ -30,8 +30,8 @@ export class CurseForgeService extends StatefulService implemen } private async fetchOrGetFromCache(cacheName: string, cache: Record, key: K, query: () => Promise) { - if (!cache[key]) { - const timestamp = await getAddonDatabaseTimestamp({ userAgent: this.networkManager.agents.https }) + const timestamp = await getAddonDatabaseTimestamp({ userAgent: this.networkManager.agents.https }) + if (cache[key]) { if (new Date(timestamp) > new Date(this.projectTimestamp)) { const value = await query() this.projectTimestamp = timestamp @@ -39,9 +39,14 @@ export class CurseForgeService extends StatefulService implemen this.log(`Cache missed for ${key} in ${cacheName}`) return value } + this.log(`Cache hit for ${key} in ${cacheName}`) + return cache[key] } - this.log(`Cache hit for ${key} in ${cacheName}`) - return cache[key] + const value = await query() + this.projectTimestamp = timestamp + cache[key] = value + this.log(`Cache missed for ${key} in ${cacheName}`) + return value } @Singleton()