diff --git a/lib/LeaderboardService.js b/lib/LeaderboardService.js index 89e24c43..59e69535 100644 --- a/lib/LeaderboardService.js +++ b/lib/LeaderboardService.js @@ -1,3 +1,5 @@ +const leaderboardTTL = 60 * 60 * 4 // 4 hours ttl as a relaxation for https://github.com/FAForever/website/issues/482 + class LeaderboardService { constructor(cacheService, mutexService, leaderboardRepository, lockTimeout = 3000) { this.lockTimeout = lockTimeout @@ -26,7 +28,7 @@ class LeaderboardService { await this.mutexService.acquire(async () => { const result = await this.leaderboardRepository.fetchLeaderboard(id) - this.cacheService.set(cacheKey, result); + this.cacheService.set(cacheKey, result, leaderboardTTL); }) return this.getLeaderboard(id) diff --git a/tests/LeaderboardService.test.js b/tests/LeaderboardService.test.js index 410158af..5ae0545b 100644 --- a/tests/LeaderboardService.test.js +++ b/tests/LeaderboardService.test.js @@ -122,7 +122,7 @@ test('full scenario', async () => { expect(cacheSetSpy).toHaveBeenCalledTimes(1); const date = new Date() - date.setSeconds(date.getSeconds() + 301) + date.setSeconds(date.getSeconds() + (60 * 60 * 4) + 1) jest.setSystemTime(date); // start another with when the cache is stale