From 499fcb6fa5690c3e6dc43eb08f6a39f47d98c710 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 13 Apr 2024 18:15:03 +0100 Subject: [PATCH] cleanup cache --- .../fascinated/common/CacheInformation.java | 48 --------------- .../cc/fascinated/common/CachedResponse.java | 59 +++++++++++++++++++ .../model/cache/CachedEndpointStatus.java | 4 +- .../model/cache/CachedMinecraftServer.java | 4 +- .../fascinated/model/cache/CachedPlayer.java | 4 +- .../model/cache/CachedPlayerName.java | 4 +- .../model/cache/CachedResponse.java | 16 ----- 7 files changed, 67 insertions(+), 72 deletions(-) delete mode 100644 src/main/java/cc/fascinated/common/CacheInformation.java create mode 100644 src/main/java/cc/fascinated/common/CachedResponse.java delete mode 100644 src/main/java/cc/fascinated/model/cache/CachedResponse.java diff --git a/src/main/java/cc/fascinated/common/CacheInformation.java b/src/main/java/cc/fascinated/common/CacheInformation.java deleted file mode 100644 index 7d908bc..0000000 --- a/src/main/java/cc/fascinated/common/CacheInformation.java +++ /dev/null @@ -1,48 +0,0 @@ -package cc.fascinated.common; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@AllArgsConstructor @Getter @Setter -public class CacheInformation { - /** - * Whether this request is cached. - */ - private boolean cached; - - /** - * The unix timestamp of when this was cached. - */ - private long cachedTime; - - /** - * Create a new cache information object with the default values. - *

- * The default values are: - *
- *

- *
- *

- * - * @return the default cache information object - */ - public static CacheInformation defaultCache() { - return new CacheInformation(true, System.currentTimeMillis()); - } - - /** - * Sets if this request is cached. - * - * @param cached the new value of if this request is cached - */ - public void setCached(boolean cached) { - this.cached = cached; - if (!cached) { - cachedTime = -1; - } - } -} diff --git a/src/main/java/cc/fascinated/common/CachedResponse.java b/src/main/java/cc/fascinated/common/CachedResponse.java new file mode 100644 index 0000000..b0dc16a --- /dev/null +++ b/src/main/java/cc/fascinated/common/CachedResponse.java @@ -0,0 +1,59 @@ +package cc.fascinated.common; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@AllArgsConstructor @NoArgsConstructor +@Getter +public class CachedResponse { + + /** + * The cache information for this response. + */ + private Cache cache; + + @AllArgsConstructor @Getter @Setter + public static class Cache { + /** + * Whether this request is cached. + */ + private boolean cached; + + /** + * The unix timestamp of when this was cached. + */ + private long cachedTime; + + /** + * Create a new cache information object with the default values. + *

+ * The default values are: + *
+ *

+ *
+ *

+ * + * @return the default cache information object + */ + public static Cache defaultCache() { + return new Cache(true, System.currentTimeMillis()); + } + + /** + * Sets if this request is cached. + * + * @param cached the new value of if this request is cached + */ + public void setCached(boolean cached) { + this.cached = cached; + if (!cached) { + cachedTime = -1; + } + } + } +} diff --git a/src/main/java/cc/fascinated/model/cache/CachedEndpointStatus.java b/src/main/java/cc/fascinated/model/cache/CachedEndpointStatus.java index 1f5c9ed..c9df8e9 100644 --- a/src/main/java/cc/fascinated/model/cache/CachedEndpointStatus.java +++ b/src/main/java/cc/fascinated/model/cache/CachedEndpointStatus.java @@ -1,6 +1,6 @@ package cc.fascinated.model.cache; -import cc.fascinated.common.CacheInformation; +import cc.fascinated.common.CachedResponse; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.*; import org.springframework.data.annotation.Id; @@ -26,7 +26,7 @@ public class CachedEndpointStatus extends CachedResponse implements Serializable private Map endpoints; public CachedEndpointStatus(@NonNull String id, Map endpoints) { - super(CacheInformation.defaultCache()); + super(Cache.defaultCache()); this.id = id; this.endpoints = endpoints; } diff --git a/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java b/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java index 4e5b4e8..5a10ea0 100644 --- a/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java +++ b/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java @@ -1,6 +1,6 @@ package cc.fascinated.model.cache; -import cc.fascinated.common.CacheInformation; +import cc.fascinated.common.CachedResponse; import cc.fascinated.model.server.MinecraftServer; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.*; @@ -29,7 +29,7 @@ public class CachedMinecraftServer extends CachedResponse implements Serializabl private MinecraftServer server; public CachedMinecraftServer(@NonNull String id, @NonNull MinecraftServer server) { - super(CacheInformation.defaultCache()); + super(Cache.defaultCache()); this.id = id; this.server = server; } diff --git a/src/main/java/cc/fascinated/model/cache/CachedPlayer.java b/src/main/java/cc/fascinated/model/cache/CachedPlayer.java index 4b92660..2f47cbc 100644 --- a/src/main/java/cc/fascinated/model/cache/CachedPlayer.java +++ b/src/main/java/cc/fascinated/model/cache/CachedPlayer.java @@ -1,6 +1,6 @@ package cc.fascinated.model.cache; -import cc.fascinated.common.CacheInformation; +import cc.fascinated.common.CachedResponse; import cc.fascinated.model.player.Player; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; @@ -33,7 +33,7 @@ public class CachedPlayer extends CachedResponse implements Serializable { private Player player; public CachedPlayer(UUID uniqueId, Player player) { - super(CacheInformation.defaultCache()); + super(Cache.defaultCache()); this.uniqueId = uniqueId; this.player = player; } diff --git a/src/main/java/cc/fascinated/model/cache/CachedPlayerName.java b/src/main/java/cc/fascinated/model/cache/CachedPlayerName.java index c2b5230..2382565 100644 --- a/src/main/java/cc/fascinated/model/cache/CachedPlayerName.java +++ b/src/main/java/cc/fascinated/model/cache/CachedPlayerName.java @@ -1,6 +1,6 @@ package cc.fascinated.model.cache; -import cc.fascinated.common.CacheInformation; +import cc.fascinated.common.CachedResponse; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; import lombok.ToString; @@ -33,7 +33,7 @@ public class CachedPlayerName extends CachedResponse { private final UUID uniqueId; public CachedPlayerName(String id, String username, UUID uniqueId) { - super(CacheInformation.defaultCache()); + super(Cache.defaultCache()); this.id = id; this.username = username; this.uniqueId = uniqueId; diff --git a/src/main/java/cc/fascinated/model/cache/CachedResponse.java b/src/main/java/cc/fascinated/model/cache/CachedResponse.java deleted file mode 100644 index b2470eb..0000000 --- a/src/main/java/cc/fascinated/model/cache/CachedResponse.java +++ /dev/null @@ -1,16 +0,0 @@ -package cc.fascinated.model.cache; - -import cc.fascinated.common.CacheInformation; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@AllArgsConstructor @NoArgsConstructor -@Getter -public class CachedResponse { - - /** - * The cache information for this response. - */ - private CacheInformation cache; -}