api: make items cache for longer
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 30s

This commit is contained in:
Lee 2024-08-05 08:37:49 +01:00
parent 21b6de0f15
commit 1f1c55d41f
2 changed files with 5 additions and 5 deletions

@ -34,8 +34,8 @@ public class ScoreSaberService {
private final Map<String, ScoreSaberLeaderboardToken> leaderboardCache = ExpiringMap.builder()
.maxSize(5_000)
.expirationPolicy(ExpirationPolicy.CREATED)
.expiration(30, TimeUnit.MINUTES)
.expirationPolicy(ExpirationPolicy.ACCESSED)
.expiration(1, TimeUnit.DAYS)
.build();
/**
@ -79,12 +79,12 @@ public class ScoreSaberService {
* @throws BadRequestException if an error occurred while getting the leaderboard
*/
public ScoreSaberLeaderboardToken getLeaderboard(String leaderboardId, boolean bypassCache) {
if (leaderboardCache.containsKey(leaderboardId) && !bypassCache) { // The leaderboard is cached
if (leaderboardCache.containsKey(leaderboardId) && !bypassCache) { // The leaderboard is cached locally (very fast)
return leaderboardCache.get(leaderboardId);
}
Optional<ScoreSaberLeaderboardToken> leaderboardOptional = leaderboardRepository.findById(leaderboardId);
if (leaderboardOptional.isPresent() && !bypassCache) { // The leaderboard is cached
if (leaderboardOptional.isPresent() && !bypassCache) { // The leaderboard is cached in the database
ScoreSaberLeaderboardToken leaderboard = leaderboardOptional.get();
leaderboardCache.put(leaderboardId, leaderboard);
return leaderboard;

@ -46,7 +46,7 @@ public class UserService {
private final Map<String, User> userCache = ExpiringMap.builder()
.maxSize(5_000)
.expirationPolicy(ExpirationPolicy.ACCESSED)
.expiration(1, TimeUnit.HOURS)
.expiration(1, TimeUnit.DAYS)
.build();
@Autowired