Package net.dv8tion.jda.api.utils
Interface MemberCachePolicy
-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface MemberCachePolicy
Policy which decides whether a member (and respective user) should be kept in cache.
This will be called throughout JDA when a member gets constructed or modified and allows for a dynamically adjusting cache of users.When
Guild.pruneMemberCache()is called, the configured policy will be used to unload any members that the policy has decided not to cache.If
GUILD_MEMBERSintent is disabled you should not useALLorONLINE. This intent enables guild member leave events which are required to remove members from cache properly.- Since:
- 4.2.0
- See Also:
DEFAULT,NONE,ALL,OWNER,VOICE,ONLINE,or(MemberCachePolicy),and(MemberCachePolicy),any(MemberCachePolicy, MemberCachePolicy...),all(MemberCachePolicy, MemberCachePolicy...)
-
-
Field Summary
Fields Modifier and Type Field Description static MemberCachePolicyALLEnable all member caching.static MemberCachePolicyDEFAULTThe default policy to use withJDABuilder.createDefault(String).static MemberCachePolicyNONEDisable all member cachingstatic MemberCachePolicyONLINECache online/idle/dnd users.static MemberCachePolicyOWNERCache owner of the guild.static MemberCachePolicyVOICECache members who are connected to a voice channel.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static MemberCachePolicyall(MemberCachePolicy policy, MemberCachePolicy... policies)Composes a policy which requires multiple other policies.default MemberCachePolicyand(MemberCachePolicy policy)Convenience method to require another policy.static MemberCachePolicyany(MemberCachePolicy policy, MemberCachePolicy... policies)Composes a policy by concatenating multiple other policies.booleancacheMember(Member member)Idempotent (ideally pure) function which decided whether to cache the provided member or not.default MemberCachePolicyor(MemberCachePolicy policy)Convenience method to concatenate another policy.
-
-
-
Field Detail
-
NONE
static final MemberCachePolicy NONE
Disable all member caching
-
ALL
static final MemberCachePolicy ALL
Enable all member caching.Not recommended without
GUILD_MEMBERSintent enabled. The api will only send the guild member leave events when this intent is enabled. Without those events the members will stay in cache indefinitely.
-
OWNER
static final MemberCachePolicy OWNER
Cache owner of the guild. This simply checksMember.isOwner().
-
ONLINE
static final MemberCachePolicy ONLINE
Cache online/idle/dnd users.
RequiresGatewayIntent.GUILD_PRESENCESto be enabled.Not recommended without
GUILD_MEMBERSintent enabled. The api will only send the guild member leave events when this intent is enabled. Without those events the members will stay in cache indefinitely.
-
VOICE
static final MemberCachePolicy VOICE
Cache members who are connected to a voice channel.
RequiresGatewayIntent.GUILD_VOICE_STATESandCacheFlag.VOICE_STATEto be enabled.
-
DEFAULT
static final MemberCachePolicy DEFAULT
The default policy to use withJDABuilder.createDefault(String).
This is identical toVOICE.or(OWNER).
-
-
Method Detail
-
cacheMember
boolean cacheMember(@Nonnull Member member)
Idempotent (ideally pure) function which decided whether to cache the provided member or not.
The function should avoid throwing any exceptions or blocking.- Parameters:
member- The member- Returns:
- True, if the member should be cached
-
or
@Nonnull default MemberCachePolicy or(@Nonnull MemberCachePolicy policy)
Convenience method to concatenate another policy.
This is identical to(member) -> policy1.cacheMember(member) || policy2.cacheMember(member).- Parameters:
policy- The policy to concat- Returns:
- New policy which combines both using a logical OR
- Throws:
IllegalArgumentException- If the provided policy is null
-
and
@Nonnull default MemberCachePolicy and(@Nonnull MemberCachePolicy policy)
Convenience method to require another policy.
This is identical to(member) -> policy1.cacheMember(member) && policy2.cacheMember(member).- Parameters:
policy- The policy to require in addition to this one- Returns:
- New policy which combines both using a logical AND
- Throws:
IllegalArgumentException- If the provided policy is null
-
any
@Nonnull static MemberCachePolicy any(@Nonnull MemberCachePolicy policy, @Nonnull MemberCachePolicy... policies)
Composes a policy by concatenating multiple other policies.
This is logically identical topolicy1 || policy2 || policy3 || ... || policyN.- Parameters:
policy- The first policypolicies- The other policies- Returns:
- New policy which combines all provided polices using a logical OR
-
all
@Nonnull static MemberCachePolicy all(@Nonnull MemberCachePolicy policy, @Nonnull MemberCachePolicy... policies)
Composes a policy which requires multiple other policies.
This is logically identical topolicy1 && policy2 && policy3 && ... && policyN.- Parameters:
policy- The first policypolicies- The other policies- Returns:
- New policy which combines all provided polices using a logical AND
-
-