Skip to content

Use JDA's LRU MemberCachePolicy instead of caching everything at startup - #5006

Open
wholton with Copilot wants to merge 4 commits into
masterfrom
copilot/remove-caching-of-members
Open

Use JDA's LRU MemberCachePolicy instead of caching everything at startup#5006
wholton with Copilot wants to merge 4 commits into
masterfrom
copilot/remove-caching-of-members

Conversation

Copilot AI commented May 8, 2026

Copy link
Copy Markdown
Contributor

JDA already provides MemberCachePolicy.lru(n) and cache-aware CacheRestAction retrieval — no need to layer a custom Caffeine cache on top, or manually pre-check the JDA cache before calling retrieve*.

Changes

  • MemberCachePolicy.lru(20_000) replaces MemberCachePolicy.ALL — JDA manages a bounded LRU eviction cache natively, capping memory without unbounded growth
  • Simplified getMemberById / getUserById — removed manual getMemberById() / getUserById() pre-checks; retrieveMemberById() and retrieveUserById() return CacheRestAction which already hits the cache before making a REST call
// Before: redundant manual cache check + REST fallback
Member member = guild.getMemberById(userId);
if (member != null) return member;
return guild.retrieveMemberById(userId).complete();

// After: CacheRestAction handles cache + REST in one call
return guild.retrieveMemberById(userId).complete();

@wholton wholton changed the title Use JDA's built-in LRU MemberCachePolicy instead of a parallel Caffeine cache Use JDA's LRU MemberCachePolicy instead of caching everything at startup May 8, 2026
@wholton
wholton marked this pull request as ready for review May 8, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants