From c07553e496a7861717bef4405552d668803c5a9b Mon Sep 17 00:00:00 2001 From: sysnote8main Date: Sun, 6 Oct 2024 16:29:16 +0900 Subject: [PATCH] [Change] Use Instance for CacheManager --- .../lgw/rankingdisplayer/RankingDisplayer.java | 4 ++-- .../rankingdisplayer/manager/CacheManager.java | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/jp/azisaba/lgw/rankingdisplayer/RankingDisplayer.java b/src/main/java/jp/azisaba/lgw/rankingdisplayer/RankingDisplayer.java index 09fed25..a81f40a 100644 --- a/src/main/java/jp/azisaba/lgw/rankingdisplayer/RankingDisplayer.java +++ b/src/main/java/jp/azisaba/lgw/rankingdisplayer/RankingDisplayer.java @@ -35,8 +35,8 @@ public void onEnable() { // KDStatusReloaded API Setup KDSAPI.loadPlugin(getLogger()); - // Setup cache - cache = new CacheManager(getLogger()); + // Setup cacheManager's logger + CacheManager.getInstance().setLogger(getLogger()); // Events listener = new DisplayListener(this); diff --git a/src/main/java/jp/azisaba/lgw/rankingdisplayer/manager/CacheManager.java b/src/main/java/jp/azisaba/lgw/rankingdisplayer/manager/CacheManager.java index 7e18e62..701b19c 100644 --- a/src/main/java/jp/azisaba/lgw/rankingdisplayer/manager/CacheManager.java +++ b/src/main/java/jp/azisaba/lgw/rankingdisplayer/manager/CacheManager.java @@ -3,7 +3,9 @@ import jp.azisaba.lgw.kdstatus.sql.KillRankingData; import jp.azisaba.lgw.rankingdisplayer.integration.KDSAPI; import jp.azisaba.lgw.rankingdisplayer.ranking.RankingType; +import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -16,9 +18,16 @@ @RequiredArgsConstructor public class CacheManager { - private final Logger logger; + @Getter + private static final CacheManager Instance = new CacheManager(); + @Setter + private Logger logger; private final long cacheHoldMilliSec = 1000 * 10; - private final HashMap> cache = new HashMap<>(); + + private final HashMap> killRankingCache = new HashMap<>(); + private final HashMap playerRankingCache = new HashMap<>(); + private final HashMap playerKillCountCache = new HashMap<>(); + private final HashMap lastUpdated = new HashMap<>(); // TODO move this to config @@ -41,7 +50,7 @@ private synchronized void updateCache(RankingType type) { if(dataList.isEmpty()) { logger.warning("Failed to get top kill ranking"); } else { - cache.put(type, dataList); + killRankingCache.put(type, dataList); } lastUpdated.put(type, System.currentTimeMillis()); } @@ -53,7 +62,7 @@ public List getRankingAsArray(RankingType type, Player p) { boolean containsHim = false; if(isNeedToUpdateCache(type)) updateCache(type); - List dataList = cache.get(type); + List dataList = killRankingCache.get(type); int count = 0; for(KillRankingData data: dataList) { if(count >= RANKING_SIZE) {