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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user