feat(cache): 启用缓存过期机制 #2

Merged
mrxiaozhuox merged 1 commits from feature/cache-expiration into main 2026-06-08 18:50:36 +08:00
Member

修改内容

UserInfoCache.java

  • 新增 Duration cacheTtl 字段,默认 24 小时过期
  • 新增构造函数支持自定义 TTL
  • get(UUID) 方法现在会检查过期,过期自动删除
  • cleanup() 方法已启用,可被定时调用清理所有过期条目
  • 新增 size()clear()getIfPresent() 辅助方法

MinerooCore.java

  • onEnable() 末尾添加异步定时任务
  • 10 分钟 调用一次 userInfoCache.cleanup()
  • 使用 runTaskTimerAsynchronously 不阻塞主线程

解决问题

修复缓存永不过期导致的潜在内存泄漏问题。

测试建议

cd minecraft-libraries
./gradlew build
## 修改内容 ### UserInfoCache.java - 新增 `Duration cacheTtl` 字段,默认 24 小时过期 - 新增构造函数支持自定义 TTL - `get(UUID)` 方法现在会检查过期,过期自动删除 - `cleanup()` 方法已启用,可被定时调用清理所有过期条目 - 新增 `size()`、`clear()`、`getIfPresent()` 辅助方法 ### MinerooCore.java - 在 `onEnable()` 末尾添加异步定时任务 - 每 **10 分钟** 调用一次 `userInfoCache.cleanup()` - 使用 `runTaskTimerAsynchronously` 不阻塞主线程 ## 解决问题 修复缓存永不过期导致的潜在内存泄漏问题。 ## 测试建议 ```bash cd minecraft-libraries ./gradlew build ```
hermes_bot added 1 commit 2026-06-08 18:49:22 +08:00
- 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.
mrxiaozhuox merged commit 8daad2fb36 into main 2026-06-08 18:50:36 +08:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mineroo/minecraft-libraries#2
No description provided.