feat(cache): enable cache expiration with TTL support

- UserInfoCache now supports configurable TTL (default 24h)
- get(UUID) returns null and removes expired entries automatically
- cleanup() method is now enabled for batch cleanup
- Added scheduled cleanup task in MinerooCore (every 10 minutes)
- Added size(), clear(), and getIfPresent() helper methods

This fixes potential memory leaks from never-expiring cache entries.
This commit is contained in:
2026-06-08 18:48:34 +08:00
parent f931b4feaf
commit 818ad69ce7
2 changed files with 62 additions and 19 deletions

View File

@@ -77,6 +77,14 @@ public class MinerooCore extends JavaPlugin implements Listener {
long period = 20L * 90;
scheduler.runTaskTimer(this, new ReportPlayersTask(this, scheduler), 20L * 30, period);
}
// Schedule cache cleanup task (every 10 minutes)
getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
if (this.userInfoCache != null) {
this.userInfoCache.cleanup();
getLogger().fine("UserInfoCache cleanup completed, size: " + this.userInfoCache.size());
}
}, 20L * 60 * 10, 20L * 60 * 10); // 10 minutes
}
@Override