cleanup cache
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m50s

This commit is contained in:
Lee 2024-04-13 18:15:03 +01:00
parent edb02c2ba1
commit 499fcb6fa5
7 changed files with 67 additions and 72 deletions

@ -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.
* <p>
* The default values are:
* <br>
* <ul>
* <li>cached: true</li>
* <li>cachedAt: {@link System#currentTimeMillis()}</li>
* </ul>
* <br>
* </p>
*
* @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;
}
}
}

@ -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.
* <p>
* The default values are:
* <br>
* <ul>
* <li>cached: true</li>
* <li>cachedAt: {@link System#currentTimeMillis()}</li>
* </ul>
* <br>
* </p>
*
* @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;
}
}
}
}

@ -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<String, Status> endpoints;
public CachedEndpointStatus(@NonNull String id, Map<String, Status> endpoints) {
super(CacheInformation.defaultCache());
super(Cache.defaultCache());
this.id = id;
this.endpoints = endpoints;
}

@ -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;
}

@ -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;
}

@ -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;

@ -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;
}