From 8216ec79435ace0bc449eae729a77227f6a7ce86 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 13 Apr 2024 17:17:13 +0100 Subject: [PATCH] clean up cache info --- .../model/cache/CachedEndpointStatus.java | 18 ++++++++++-------- .../model/cache/CachedMinecraftServer.java | 18 ++++++++++-------- .../fascinated/model/cache/CachedPlayer.java | 14 ++++++++------ .../fascinated/model/cache/CachedResponse.java | 15 +++++++++++++++ .../cc/fascinated/model/player/Player.java | 9 +++++---- .../cc/fascinated/service/MojangService.java | 3 +-- .../cc/fascinated/service/PlayerService.java | 3 +-- .../cc/fascinated/service/ServerService.java | 3 +-- 8 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 src/main/java/cc/fascinated/model/cache/CachedResponse.java diff --git a/src/main/java/cc/fascinated/model/cache/CachedEndpointStatus.java b/src/main/java/cc/fascinated/model/cache/CachedEndpointStatus.java index fa4bc08..df22b9f 100644 --- a/src/main/java/cc/fascinated/model/cache/CachedEndpointStatus.java +++ b/src/main/java/cc/fascinated/model/cache/CachedEndpointStatus.java @@ -8,25 +8,27 @@ import org.springframework.data.redis.core.RedisHash; import java.io.Serializable; import java.util.Map; -@AllArgsConstructor @Setter @Getter @ToString +@Setter @Getter @ToString +@NoArgsConstructor @RedisHash(value = "mojangEndpointStatus", timeToLive = 60L) // 1 minute (in seconds) -public final class CachedEndpointStatus implements Serializable { +public final class CachedEndpointStatus extends CachedResponse implements Serializable { /** * The id for this endpoint cache. */ @Id @NonNull @JsonIgnore - private final String id; + private String id; /** * The list of endpoints and their status. */ - private final Map endpoints; + private Map endpoints; - /** - * The cache information about the request. - */ - private CacheInformation cache; + public CachedEndpointStatus(@NonNull String id, Map endpoints) { + super(CacheInformation.defaultCache()); + this.id = id; + this.endpoints = endpoints; + } public enum Status { /** diff --git a/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java b/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java index 4545452..0650c56 100644 --- a/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java +++ b/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java @@ -11,23 +11,25 @@ import java.io.Serializable; /** * @author Braydon */ -@AllArgsConstructor @Setter @Getter @ToString +@Setter @Getter @ToString +@NoArgsConstructor @RedisHash(value = "server", timeToLive = 60L) // 1 minute (in seconds) -public final class CachedMinecraftServer implements Serializable { +public final class CachedMinecraftServer extends CachedResponse implements Serializable { /** * The id of this cached server. */ @Id @NonNull @JsonIgnore - private final String id; + private String id; /** * The cached server. */ @NonNull - private final MinecraftServer server; + private MinecraftServer server; - /** - * The cache information about the request. - */ - private CacheInformation cache; + public CachedMinecraftServer(@NonNull String id, @NonNull MinecraftServer server) { + super(CacheInformation.defaultCache()); + this.id = id; + this.server = server; + } } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/model/cache/CachedPlayer.java b/src/main/java/cc/fascinated/model/cache/CachedPlayer.java index 955e031..a901c7a 100644 --- a/src/main/java/cc/fascinated/model/cache/CachedPlayer.java +++ b/src/main/java/cc/fascinated/model/cache/CachedPlayer.java @@ -4,6 +4,7 @@ import cc.fascinated.model.player.Player; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import org.springframework.data.annotation.Id; import org.springframework.data.redis.core.RedisHash; @@ -17,9 +18,9 @@ import java.util.UUID; * @author Braydon */ @Setter @Getter -@AllArgsConstructor +@NoArgsConstructor @RedisHash(value = "player", timeToLive = 60L * 60L) // 1 hour (in seconds) -public final class CachedPlayer implements Serializable { +public final class CachedPlayer extends CachedResponse implements Serializable { /** * The unique id of the player. */ @@ -31,8 +32,9 @@ public final class CachedPlayer implements Serializable { */ private Player player; - /** - * The cache information about the request. - */ - private CacheInformation cache; + public CachedPlayer(UUID uniqueId, Player player) { + super(CacheInformation.defaultCache()); + this.uniqueId = uniqueId; + this.player = player; + } } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/model/cache/CachedResponse.java b/src/main/java/cc/fascinated/model/cache/CachedResponse.java new file mode 100644 index 0000000..1d1b07d --- /dev/null +++ b/src/main/java/cc/fascinated/model/cache/CachedResponse.java @@ -0,0 +1,15 @@ +package cc.fascinated.model.cache; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor @NoArgsConstructor +@Getter +public class CachedResponse { + + /** + * The cache information for this response. + */ + private CacheInformation cache; +} diff --git a/src/main/java/cc/fascinated/model/player/Player.java b/src/main/java/cc/fascinated/model/player/Player.java index a5dec85..7c4608c 100644 --- a/src/main/java/cc/fascinated/model/player/Player.java +++ b/src/main/java/cc/fascinated/model/player/Player.java @@ -6,26 +6,27 @@ import cc.fascinated.model.mojang.MojangProfile; import cc.fascinated.model.skin.Skin; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import java.util.UUID; -@Getter @AllArgsConstructor +@Getter @AllArgsConstructor @NoArgsConstructor public class Player { /** * The UUID of the player */ - private final UUID uniqueId; + private UUID uniqueId; /** * The trimmed UUID of the player */ - private final String trimmedUniqueId; + private String trimmedUniqueId; /** * The username of the player */ - private final String username; + private String username; /** * The skin of the player, null if the diff --git a/src/main/java/cc/fascinated/service/MojangService.java b/src/main/java/cc/fascinated/service/MojangService.java index 20ffef3..7d2eca2 100644 --- a/src/main/java/cc/fascinated/service/MojangService.java +++ b/src/main/java/cc/fascinated/service/MojangService.java @@ -231,8 +231,7 @@ public class MojangService { log.info("Fetched Mojang API status for {} endpoints", endpoints.size()); CachedEndpointStatus status = new CachedEndpointStatus( MOJANG_ENDPOINT_STATUS_KEY, - endpoints, - CacheInformation.defaultCache() + endpoints ); mojangEndpointStatusRepository.save(status); status.getCache().setCached(false); diff --git a/src/main/java/cc/fascinated/service/PlayerService.java b/src/main/java/cc/fascinated/service/PlayerService.java index 3231036..ec34cb5 100644 --- a/src/main/java/cc/fascinated/service/PlayerService.java +++ b/src/main/java/cc/fascinated/service/PlayerService.java @@ -82,8 +82,7 @@ public class PlayerService { skinAndCape.getLeft(), // Skin skinAndCape.getRight(), // Cape mojangProfile.getProperties() // Raw properties - ), - CacheInformation.defaultCache() // Cache time + ) ); playerCacheRepository.save(player); diff --git a/src/main/java/cc/fascinated/service/ServerService.java b/src/main/java/cc/fascinated/service/ServerService.java index 346ad85..276d11a 100644 --- a/src/main/java/cc/fascinated/service/ServerService.java +++ b/src/main/java/cc/fascinated/service/ServerService.java @@ -89,8 +89,7 @@ public class ServerService { CachedMinecraftServer server = new CachedMinecraftServer( key, - platform.getPinger().ping(hostname, ip, port, records.toArray(new DNSRecord[0])), - CacheInformation.defaultCache() + platform.getPinger().ping(hostname, ip, port, records.toArray(new DNSRecord[0])) ); // Check if the server is blocked by Mojang