Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions src/main/java/net/coreprotect/thread/CacheHandler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.coreprotect.thread;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -15,18 +13,18 @@

public class CacheHandler implements Runnable {

public static Map<String, Object[]> lookupCache = Collections.synchronizedMap(new HashMap<>());
public static Map<String, Object[]> breakCache = Collections.synchronizedMap(new HashMap<>());
public static Map<String, Object[]> interactCache = Collections.synchronizedMap(new HashMap<>());
public static Map<String, Object[]> entityCache = Collections.synchronizedMap(new HashMap<>());
public static ConcurrentHashMap<String, Object[]> pistonCache = new ConcurrentHashMap<>(16, 0.75f, 2);
public static ConcurrentHashMap<String, Object[]> spreadCache = new ConcurrentHashMap<>(16, 0.75f, 2);
public static ConcurrentHashMap<String, Object[]> containerDuplicateCache = new ConcurrentHashMap<>(16, 0.75f, 2);
public static ConcurrentHashMap<String, Object[]> flowDuplicateCache = new ConcurrentHashMap<>(16, 0.75f, 2);
public static ConcurrentHashMap<String, Object[]> bonemealDuplicateCache = new ConcurrentHashMap<>(16, 0.75f, 2);
public static ConcurrentHashMap<String, Object[]> entityKillDuplicateCache = new ConcurrentHashMap<>(16, 0.75f, 2);
public static ConcurrentHashMap<String, Object[]> redstoneCache = new ConcurrentHashMap<>(16, 0.75f, 2);
public static ConcurrentHashMap<String, Object[]> fallingBlockSpawnCache = new ConcurrentHashMap<>(16, 0.75f, 2);
public static Map<String, Object[]> lookupCache = new ConcurrentHashMap<>();
public static Map<String, Object[]> breakCache = new ConcurrentHashMap<>();
public static Map<String, Object[]> interactCache = new ConcurrentHashMap<>();
public static Map<String, Object[]> entityCache = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Object[]> pistonCache = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Object[]> spreadCache = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Object[]> containerDuplicateCache = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Object[]> flowDuplicateCache = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Object[]> bonemealDuplicateCache = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Object[]> entityKillDuplicateCache = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Object[]> redstoneCache = new ConcurrentHashMap<>();
public static ConcurrentHashMap<String, Object[]> fallingBlockSpawnCache = new ConcurrentHashMap<>();

private static volatile Thread thread;

Expand Down Expand Up @@ -156,25 +154,15 @@ public void run() {
}

int timestamp = (int) (System.currentTimeMillis() / 1000L) - scanTime;
Iterator<Entry> iterator = cache.entrySet().iterator();
while (iterator.hasNext()) {
cache.values().removeIf(value -> {
try {
Map.Entry entry = iterator.next();
Object[] data = (Object[]) entry.getValue();
Object[] data = (Object[]) value;
int time = (data[0] instanceof Long) ? (int) ((long) data[0] / 1000L) : (int) data[0];

if (time < timestamp) {
try {
iterator.remove();
}
catch (Exception e) {
}
}
}
catch (Exception e) {
break;
return time < timestamp;
} catch (Exception e) {
return true; // malformed entry
}
}
});
}
}
catch (InterruptedException e) {
Expand Down
Loading