mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-05-31 09:31:54 +00:00
Fixing potential memory leak
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package dev.brighten.antivpn.api;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.utils.EvictingMap;
|
||||
import dev.brighten.antivpn.utils.VPNResponse;
|
||||
import dev.brighten.antivpn.utils.json.JSONException;
|
||||
import lombok.Getter;
|
||||
@@ -15,7 +16,7 @@ import java.util.function.Consumer;
|
||||
public abstract class VPNExecutor {
|
||||
public static ExecutorService threadExecutor = Executors.newSingleThreadExecutor();
|
||||
|
||||
public static final Map<String, VPNResponse> responseCache = new HashMap<>();
|
||||
public static final Map<String, VPNResponse> responseCache = new EvictingMap<>(5000);
|
||||
@Getter
|
||||
private final Set<UUID> whitelisted = Collections.synchronizedSet(new HashSet<>());
|
||||
@Getter
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package dev.brighten.antivpn.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class EvictingMap<K, V> extends LinkedHashMap<K, V> {
|
||||
|
||||
@Getter
|
||||
private final int size;
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
|
||||
return size() >= size;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user