diff --git a/pom.xml b/pom.xml index 2c5d4f2f5..e65dc7aa2 100644 --- a/pom.xml +++ b/pom.xml @@ -279,5 +279,12 @@ 2.10.4 provided + + + it.unimi.dsi + fastutil + 8.3.0 + + diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 13649bb83..49b3d653b 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1073,6 +1073,8 @@ public class QuickShop extends JavaPlugin { getConfig().set("webhook.enable", false); getConfig().set("webhook.url", "https://example.com/webhookListener.php"); getConfig().set("config-version", 71); + getConfig().set("cachingpool.enable", false); + getConfig().set("cachingpool.maxsize", 100000000); selectedVersion = 71; } saveConfig(); diff --git a/src/main/java/org/maxgamer/quickshop/Util/CachingPool.java b/src/main/java/org/maxgamer/quickshop/Util/CachingPool.java new file mode 100644 index 000000000..d0714bb0c --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/Util/CachingPool.java @@ -0,0 +1,41 @@ +package org.maxgamer.quickshop.Util; + +import it.unimi.dsi.fastutil.objects.ObjectArraySet; +import org.jetbrains.annotations.NotNull; +import org.maxgamer.quickshop.QuickShop; + +import java.util.HashMap; +import java.util.Map; + +public class CachingPool { + static Map> repoForCaching = new HashMap<>(); + + public static boolean contains(@NotNull String indexName, @NotNull Object object){ + ObjectArraySet list = repoForCaching.get(indexName); + if(list == null){ + return false; + } + return list.contains(object); + } + public static boolean add(@NotNull String indexName, @NotNull Object object){ + ObjectArraySet list = repoForCaching.get(indexName); + if(list == null){ + list = new ObjectArraySet<>(); + list.add(object); + repoForCaching.put(indexName,list); + return true; + } + if(list.size() > QuickShop.instance.getConfig().getInt("cachingpool.maxsize")){ + list.clear(); + Util.debugLog("Caching pool is cleared!"); + } + return list.add(object); + } + public static boolean remove(@NotNull String indexName, @NotNull Object object){ + ObjectArraySet list = repoForCaching.get(indexName); + if(list == null){ + return false; + } + return list.remove(object); + } +} \ No newline at end of file diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index 477818a61..28bc5e09e 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -292,11 +292,11 @@ public class Util { if (b.getBlockData() instanceof Directional) { Directional directional = (Directional) b.getBlockData(); return b.getRelative(directional.getFacing().getOppositeFace()); + } else { return null; } } - /** * Return the Class name. * diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3da9108e7..0baa6b8bf 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -331,4 +331,11 @@ matcher: custommodeldata: true webhook: enable: false - url: "https://example.com/webhookListener.php" \ No newline at end of file + url: "https://example.com/webhookListener.php" +cachingpool: + # Did you want use caching pool? + # Only use it when you see some method eat too many long time, because may cause actions more slowly if you server too small. + enable: false + # How many size for caching pool? + # When objects more than this number, it will removed some old object. + maxsize: 100000000