From 805da78cad599289930776bd15309fbb335eea2b Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 26 Jun 2024 14:15:05 +0100 Subject: [PATCH] fix caching! --- .../beatsaber/scoresaber/ScoreSaberAccountToken.java | 8 +++++--- .../java/cc/fascinated/bat/service/ScoreSaberService.java | 2 ++ src/main/resources/application.yml | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/model/token/beatsaber/scoresaber/ScoreSaberAccountToken.java b/src/main/java/cc/fascinated/bat/model/token/beatsaber/scoresaber/ScoreSaberAccountToken.java index f470417..a48af98 100644 --- a/src/main/java/cc/fascinated/bat/model/token/beatsaber/scoresaber/ScoreSaberAccountToken.java +++ b/src/main/java/cc/fascinated/bat/model/token/beatsaber/scoresaber/ScoreSaberAccountToken.java @@ -3,8 +3,10 @@ package cc.fascinated.bat.model.token.beatsaber.scoresaber; import lombok.AllArgsConstructor; import lombok.Getter; +import java.io.Serializable; + @Getter -public class ScoreSaberAccountToken { +public class ScoreSaberAccountToken implements Serializable { /** * The id for this ScoreSaber account. */ @@ -89,7 +91,7 @@ public class ScoreSaberAccountToken { * The badge for this account. */ @AllArgsConstructor @Getter - public static class Badge { + public static class Badge implements Serializable { /** * The image for this badge. */ @@ -105,7 +107,7 @@ public class ScoreSaberAccountToken { * The score stats for this account. */ @AllArgsConstructor @Getter - public static class ScoreStats { + public static class ScoreStats implements Serializable { /** * The total score for this account. */ diff --git a/src/main/java/cc/fascinated/bat/service/ScoreSaberService.java b/src/main/java/cc/fascinated/bat/service/ScoreSaberService.java index a976d4d..c99494d 100644 --- a/src/main/java/cc/fascinated/bat/service/ScoreSaberService.java +++ b/src/main/java/cc/fascinated/bat/service/ScoreSaberService.java @@ -13,6 +13,7 @@ import lombok.NonNull; import lombok.SneakyThrows; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.TextMessage; @@ -43,6 +44,7 @@ public class ScoreSaberService extends TextWebSocketHandler { * @throws ResourceNotFoundException If the account is not found. * @throws cc.fascinated.bat.exception.RateLimitException If the ScoreSaber rate limit is reached. */ + @Cacheable(cacheNames = "scoreSaberAccounts", key = "#id") public ScoreSaberAccountToken getAccount(String id) { ScoreSaberAccountToken account = WebRequest.getAsEntity(String.format(GET_PLAYER_ENDPOINT, id), ScoreSaberAccountToken.class); if (account == null) { // Check if the account doesn't exist. diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 89428f2..fd1aeeb 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,7 +11,7 @@ spring: cache: type: redis redis: - time-to-live: 60000 + time-to-live: 300000 # 5 minutes redis: host: localhost port: 6379