Skip to content

Commit

Permalink
fix: Curseforge page cannot load
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed May 20, 2022
1 parent 117acce commit f861aa6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions xmcl-runtime/lib/services/CurseForgeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,23 @@ export class CurseForgeService extends StatefulService<CurseforgeState> implemen
}

private async fetchOrGetFromCache<K extends string | number, V>(cacheName: string, cache: Record<K, V>, key: K, query: () => Promise<V>) {
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
cache[key] = value
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()
Expand Down

0 comments on commit f861aa6

Please sign in to comment.