fix caching!

This commit is contained in:
Lee 2024-06-26 14:15:05 +01:00
parent 3fc26583f2
commit 805da78cad
3 changed files with 8 additions and 4 deletions

@ -3,8 +3,10 @@ package cc.fascinated.bat.model.token.beatsaber.scoresaber;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.io.Serializable;
@Getter @Getter
public class ScoreSaberAccountToken { public class ScoreSaberAccountToken implements Serializable {
/** /**
* The id for this ScoreSaber account. * The id for this ScoreSaber account.
*/ */
@ -89,7 +91,7 @@ public class ScoreSaberAccountToken {
* The badge for this account. * The badge for this account.
*/ */
@AllArgsConstructor @Getter @AllArgsConstructor @Getter
public static class Badge { public static class Badge implements Serializable {
/** /**
* The image for this badge. * The image for this badge.
*/ */
@ -105,7 +107,7 @@ public class ScoreSaberAccountToken {
* The score stats for this account. * The score stats for this account.
*/ */
@AllArgsConstructor @Getter @AllArgsConstructor @Getter
public static class ScoreStats { public static class ScoreStats implements Serializable {
/** /**
* The total score for this account. * The total score for this account.
*/ */

@ -13,6 +13,7 @@ import lombok.NonNull;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
@ -43,6 +44,7 @@ public class ScoreSaberService extends TextWebSocketHandler {
* @throws ResourceNotFoundException If the account is not found. * @throws ResourceNotFoundException If the account is not found.
* @throws cc.fascinated.bat.exception.RateLimitException If the ScoreSaber rate limit is reached. * @throws cc.fascinated.bat.exception.RateLimitException If the ScoreSaber rate limit is reached.
*/ */
@Cacheable(cacheNames = "scoreSaberAccounts", key = "#id")
public ScoreSaberAccountToken getAccount(String id) { public ScoreSaberAccountToken getAccount(String id) {
ScoreSaberAccountToken account = WebRequest.getAsEntity(String.format(GET_PLAYER_ENDPOINT, id), ScoreSaberAccountToken.class); ScoreSaberAccountToken account = WebRequest.getAsEntity(String.format(GET_PLAYER_ENDPOINT, id), ScoreSaberAccountToken.class);
if (account == null) { // Check if the account doesn't exist. if (account == null) { // Check if the account doesn't exist.

@ -11,7 +11,7 @@ spring:
cache: cache:
type: redis type: redis
redis: redis:
time-to-live: 60000 time-to-live: 300000 # 5 minutes
redis: redis:
host: localhost host: localhost
port: 6379 port: 6379