mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-25 01:49:49 -05:00
Add util for CachingPool
Former-commit-id: bc468ebc46fec40966511dbb808eee1d96d712aa [formerly e131e96327082db8ed7290ed2e9ccd676c731c4d] Former-commit-id: 6394389055a59b75709c5ed8b0c38019cf8baf27
This commit is contained in:
1 parent
09c1b3d41a
commit
323be24469
5 files changed
+59
-2
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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<Object, ObjectArraySet<Object>> repoForCaching = new HashMap<>();
|
||||
|
||||
public static boolean contains(@NotNull String indexName, @NotNull Object object){
|
||||
ObjectArraySet<Object> list = repoForCaching.get(indexName);
|
||||
if(list == null){
|
||||
return false;
|
||||
}
|
||||
return list.contains(object);
|
||||
}
|
||||
public static boolean add(@NotNull String indexName, @NotNull Object object){
|
||||
ObjectArraySet<Object> 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<Object> list = repoForCaching.get(indexName);
|
||||
if(list == null){
|
||||
return false;
|
||||
}
|
||||
return list.remove(object);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -331,4 +331,11 @@ matcher:
|
||||
custommodeldata: true
|
||||
webhook:
|
||||
enable: false
|
||||
url: "https://example.com/webhookListener.php"
|
||||
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
|
||||
Reference in new issue
Block a user