Skip to content

Commit 590b322

Browse files
committed
Adjustment to flushing skull caches
1 parent 71d95e8 commit 590b322

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

SimpleAPI/src/main/java/com/bencodez/simpleapi/skull/SkullCache.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ public class SkullCache {
3333
* accessed.
3434
*/
3535
private static final HashMap<UUID, ItemStack> skullMap = new HashMap<>();
36+
private static final HashMap<UUID, Long> timeMap = new HashMap<>();
37+
3638
private static final HashMap<String, ItemStack> skullBase64Map = new HashMap<>();
3739
private static final HashMap<String, Long> timeBase64Map = new HashMap<>();
40+
3841
private static final HashMap<String, ItemStack> skullURLMap = new HashMap<>();
3942
private static final HashMap<String, Long> timeURLMap = new HashMap<>();
40-
private static final HashMap<UUID, Long> timeMap = new HashMap<>();
4143

4244
/**
4345
* Cache a skull from a uuid.
@@ -252,6 +254,18 @@ public static void flush(long milliseconds) {
252254
timeMap.remove(uuid);
253255
}
254256
}
257+
for (String base64 : skullBase64Map.keySet()) {
258+
if (System.currentTimeMillis() - timeBase64Map.get(base64) > milliseconds) {
259+
skullBase64Map.remove(base64);
260+
timeBase64Map.remove(base64);
261+
}
262+
}
263+
for (String url : skullURLMap.keySet()) {
264+
if (System.currentTimeMillis() - timeURLMap.get(url) > milliseconds) {
265+
skullURLMap.remove(url);
266+
timeURLMap.remove(url);
267+
}
268+
}
255269
}
256270

257271
/**

SimpleAPI/src/main/java/com/bencodez/simpleapi/skull/SkullCacheHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public ItemStack getSkull(UUID uuid, String playerName) {
5353
return new ItemStack(Material.PLAYER_HEAD);
5454
}
5555
}
56+
57+
public void flushCache() {
58+
SkullCache.flushWeek();
59+
}
5660

5761
public void close() {
5862
timer.shutdownNow();

0 commit comments

Comments
 (0)