From f861aa644a835d681e82efe9b493c2c0c6946f62 Mon Sep 17 00:00:00 2001 From: CI010 Date: Fri, 20 May 2022 11:53:50 +0800 Subject: [PATCH] fix: Curseforge page cannot load --- xmcl-runtime/lib/services/CurseForgeService.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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()