Package com.mewna.catnip.cache
Class MemoryEntityCache
java.lang.Object
com.mewna.catnip.cache.MemoryEntityCache
- All Implemented Interfaces:
EntityCache
,EntityCacheWorker
- Direct Known Subclasses:
SplitMemoryEntityCache
,UnifiedMemoryEntityCache
- Since:
- 9/18/18.
- Author:
- amy
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.mewna.catnip.cache.EntityCacheWorker
EntityCacheWorker.CachedEntityState
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Map<Long,
MutableNamedCacheView<Emoji.CustomEmoji>> protected final MutableNamedCacheView<Guild>
protected final Map<Long,
MutableNamedCacheView<GuildChannel>> protected final Map<Long,
MutableNamedCacheView<Member>> protected final Map<Long,
MutableNamedCacheView<Role>> protected final AtomicReference<User>
protected final MutableCacheView<ThreadChannel.ThreadMember>
protected final Map<Long,
MutableCacheView<VoiceState>> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
bulkCacheChannels
(int shardId, Collection<GuildChannel> channels) void
bulkCacheEmoji
(int shardId, Collection<Emoji.CustomEmoji> emoji) void
bulkCacheMembers
(int shardId, Collection<Member> members) void
bulkCachePresences
(int shardId, Map<String, Presence> presences) void
bulkCacheRoles
(int shardId, Collection<Role> roles) void
bulkCacheThreadMembers
(int shardId, Collection<ThreadChannel.ThreadMember> threadMembers) void
bulkCacheUsers
(int shardId, Collection<User> users) void
bulkCacheVoiceStates
(int shardId, Collection<VoiceState> voiceStates) boolean
catnip()
io.reactivex.rxjava3.core.Maybe<GuildChannel>
channel
(long guildId, long id) Get the channel with the given ID from the guild with the given ID.protected MutableNamedCacheView<GuildChannel>
channelCache
(long guildId, boolean onlyGet) channels()
Get all guild channels cached in this entity cache.channels
(long guildId) Get all channels for the guild with the given ID.protected <T> MutableCacheView<T>
Creates a new cache view.protected MutableCacheView<UserDMChannel>
Creates a new DM channel cache view.protected MutableNamedCacheView<Emoji.CustomEmoji>
Creates a new emoji cache view.protected MutableNamedCacheView<Guild>
Creates a new guild cache view.protected MutableNamedCacheView<GuildChannel>
Creates a new guild channel cache view.protected MutableNamedCacheView<Member>
Creates a new member cache view.protected <T> MutableNamedCacheView<T>
createNamedCacheView
(Function<T, String> nameFunction) Creates a new named cache view.protected MutableCacheView<Presence>
Creates a new presence cache view.protected MutableNamedCacheView<Role>
Creates a new role cache view.protected MutableNamedCacheView<User>
Creates a new user cache view.protected MutableCacheView<VoiceState>
Creates a new voice state cache view.protected void
deleteChannelCache
(long guildId) protected void
deleteEmojiCache
(long guildId) protected void
deleteMemberCache
(long guildId) protected void
deleteRoleCache
(long guildId) protected void
deleteThreadCache
(long guildId) protected void
deleteVoiceStateCache
(long guildId) protected abstract MutableCacheView<UserDMChannel>
dmChannelCache
(int shardId) io.reactivex.rxjava3.core.Maybe<Emoji.CustomEmoji>
emoji
(long guildId, long id) Get the custom emojis with the given ID from the guild with the given ID.protected MutableNamedCacheView<Emoji.CustomEmoji>
emojiCache
(long guildId, boolean onlyGet) emojis()
Get all emojis cached in this entity cache.emojis
(long guildId) Get all custom emojis for the guild with the given ID.io.reactivex.rxjava3.core.Maybe<Guild>
guild
(long id) Get the guild with the specified ID.protected MutableNamedCacheView<Guild>
guildCache
(int shardId) guilds()
void
invalidateShard
(int id) io.reactivex.rxjava3.core.Maybe<Member>
member
(long guildId, long id) Get the member with the given ID from the guild with the given ID.protected MutableNamedCacheView<Member>
memberCache
(long guildId, boolean onlyGet) Function used to map members to their name, for named cache views.members()
Get all members cached in this entity cache.members
(long guildId) Get all members for the guild with the given ID.protected <T> io.reactivex.rxjava3.core.Maybe<T>
or
(T data) protected <T> io.reactivex.rxjava3.core.Maybe<T>
or
(T data, T def) io.reactivex.rxjava3.core.Maybe<Presence>
presence
(long id) Get the presence for the user with the specified ID.protected abstract MutableCacheView<Presence>
presenceCache
(int shardId) io.reactivex.rxjava3.core.Maybe<Role>
role
(long guildId, long id) Get the role with the given ID from the guild with the given ID.protected MutableNamedCacheView<Role>
roleCache
(long guildId, boolean onlyGet) roles()
Get all roles cached in this entity cache.roles
(long guildId) Get all roles for the guild with the given ID.io.reactivex.rxjava3.core.Maybe<User>
selfUser()
protected int
shardId
(long entityId) io.reactivex.rxjava3.core.Maybe<ThreadChannel.ThreadMember>
threadMember
(long id) io.reactivex.rxjava3.core.Completable
updateCache
(String eventType, int shardId, com.grack.nanojson.JsonObject payload) Update cache with a single gateway event.io.reactivex.rxjava3.core.Maybe<User>
user
(long id) Get the user with the specified ID.protected abstract MutableNamedCacheView<User>
userCache
(int shardId) io.reactivex.rxjava3.core.Maybe<VoiceState>
voiceState
(long guildId, long id) Get the voice state for the user with the given ID, possibly in the guild with the given ID.protected MutableCacheView<VoiceState>
voiceStateCache
(long guildId, boolean onlyGet) Get all voice states for the entire bot.voiceStates
(long guildId) Get all voice states for the guild with the given ID.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.mewna.catnip.cache.EntityCache
channel, channels, emoji, emojis, guild, member, members, presence, presences, role, roles, threadMember, user, users, voiceState, voiceStates
-
Field Details
-
guildCache
-
memberCache
-
roleCache
-
guildChannelCache
-
emojiCache
-
voiceStateCache
-
threadMemberCache
-
selfUser
-
-
Constructor Details
-
MemoryEntityCache
public MemoryEntityCache()
-
-
Method Details
-
canProvidePreviousState
- Specified by:
canProvidePreviousState
in interfaceEntityCacheWorker
-
memberNameFunction
Function used to map members to their name, for named cache views. Used by the defaultcreateMemberCacheView()
andmembers()
implementations.Defaults to returning a member's effective name, which is their nickname, if present, or their username.
- Returns:
- Function used to map members to their name.
-
createGuildCacheView
Creates a new guild cache view. Subclasses can override this method to use a different cache view implementation.- Returns:
- A new guild cache view.
-
createUserCacheView
Creates a new user cache view. Subclasses can override this method to use a different cache view implementation.- Returns:
- A new user cache view.
-
createDMChannelCacheView
Creates a new DM channel cache view. Subclasses can override this method to use a different cache view implementation.- Returns:
- A new DM channel cache view.
-
createPresenceCacheView
Creates a new presence cache view. Subclasses can override this method to use a different cache view implementation.- Returns:
- A new presence cache view.
-
createGuildChannelCacheView
@Nonnull @CheckReturnValue protected MutableNamedCacheView<GuildChannel> createGuildChannelCacheView()Creates a new guild channel cache view. Subclasses can override this method to use a different cache view implementation.- Returns:
- A new guild channel cache view.
-
createRoleCacheView
Creates a new role cache view. Subclasses can override this method to use a different cache view implementation.- Returns:
- A new role cache view.
-
createMemberCacheView
Creates a new member cache view. Subclasses can override this method to use a different cache view implementation.- Returns:
- A new member cache view.
-
createEmojiCacheView
@Nonnull @CheckReturnValue protected MutableNamedCacheView<Emoji.CustomEmoji> createEmojiCacheView()Creates a new emoji cache view. Subclasses can override this method to use a different cache view implementation.- Returns:
- A new emoji cache view.
-
createVoiceStateCacheView
Creates a new voice state cache view. Subclasses can override this method to use a different cache view implementation.- Returns:
- A new voice state cache view.
-
createCacheView
Creates a new cache view. Subclasses can override this method to use a different cache view implementation.- Type Parameters:
T
- Type of the elements to be held by this view.- Returns:
- A new cache view.
-
createNamedCacheView
@Nonnull @CheckReturnValue protected <T> MutableNamedCacheView<T> createNamedCacheView(@Nonnull Function<T, String> nameFunction) Creates a new named cache view. Subclasses can override this method to use a different cache view implementation.- Type Parameters:
T
- Type of the elements to be held by this view.- Returns:
- A new named cache view.
-
userCache
-
dmChannelCache
-
presenceCache
-
guildCache
-
memberCache
-
deleteMemberCache
protected void deleteMemberCache(long guildId) -
roleCache
-
deleteRoleCache
protected void deleteRoleCache(long guildId) -
channelCache
-
deleteChannelCache
protected void deleteChannelCache(long guildId) -
emojiCache
-
deleteEmojiCache
protected void deleteEmojiCache(long guildId) -
voiceStateCache
-
deleteVoiceStateCache
protected void deleteVoiceStateCache(long guildId) -
deleteThreadCache
protected void deleteThreadCache(long guildId) -
or
protected <T> io.reactivex.rxjava3.core.Maybe<T> or(@Nullable T data, T def) -
or
protected <T> io.reactivex.rxjava3.core.Maybe<T> or(@Nullable T data) -
guild
Description copied from interface:EntityCache
Get the guild with the specified ID. May benull
.- Specified by:
guild
in interfaceEntityCache
- Parameters:
id
- The ID of the guild to fetch.- Returns:
- The guild, or
null
if it isn't cached.
-
user
Description copied from interface:EntityCache
Get the user with the specified ID. May benull
.- Specified by:
user
in interfaceEntityCache
- Parameters:
id
- The ID of the user to fetch.- Returns:
- The user, or
null
if it isn't cached.
-
presence
Description copied from interface:EntityCache
Get the presence for the user with the specified ID. May benull
.- Specified by:
presence
in interfaceEntityCache
- Parameters:
id
- The ID of the user whose presence is to be fetched.- Returns:
- The user's presence, or
null
if it isn't cached.
-
member
Description copied from interface:EntityCache
Get the member with the given ID from the guild with the given ID. May benull
.- Specified by:
member
in interfaceEntityCache
- Parameters:
guildId
- The ID of the guild the desired member is in.id
- The ID of the desired member.- Returns:
- The member, or
null
if it isn't cached.
-
role
Description copied from interface:EntityCache
Get the role with the given ID from the guild with the given ID. May benull
.- Specified by:
role
in interfaceEntityCache
- Parameters:
guildId
- The ID of the guild the desired role is from.id
- The ID of the desired role.- Returns:
- The role, or
null
if it isn't cached.
-
channel
Description copied from interface:EntityCache
Get the channel with the given ID from the guild with the given ID. May benull
.- Specified by:
channel
in interfaceEntityCache
- Parameters:
guildId
- The ID of the guild the desired channel is from.id
- The ID of the desired channel.- Returns:
- The channel, or
null
if it isn't cached.
-
emoji
Description copied from interface:EntityCache
Get the custom emojis with the given ID from the guild with the given ID. May benull
,- Specified by:
emoji
in interfaceEntityCache
- Parameters:
guildId
- The ID of the guild the desired custom emojis is from.id
- The ID of the desired custom emojis.- Returns:
- The custom emojis, or
null
if it isn't cached.
-
voiceState
Description copied from interface:EntityCache
Get the voice state for the user with the given ID, possibly in the guild with the given ID. May benull
.- Specified by:
voiceState
in interfaceEntityCache
- Parameters:
guildId
- The ID of the guild the voice state is from.id
- The ID of the user whose voice state is desired.- Returns:
- The requested voice state, or
null
if it isn't cached.
-
threadMember
- Specified by:
threadMember
in interfaceEntityCache
-
selfUser
- Specified by:
selfUser
in interfaceEntityCache
- Returns:
- The currently-logged-in user. May be
null
if no shards have logged in.
-
shardId
protected int shardId(long entityId) -
updateCache
@Nonnull public io.reactivex.rxjava3.core.Completable updateCache(@Nonnull String eventType, @Nonnegative int shardId, @Nonnull com.grack.nanojson.JsonObject payload) Description copied from interface:EntityCacheWorker
Update cache with a single gateway event.- Specified by:
updateCache
in interfaceEntityCacheWorker
- Parameters:
eventType
- Type of the event.payload
- Data payload contained in the event- Returns:
- Itself.
-
bulkCacheUsers
- Specified by:
bulkCacheUsers
in interfaceEntityCacheWorker
-
bulkCacheChannels
- Specified by:
bulkCacheChannels
in interfaceEntityCacheWorker
-
bulkCacheRoles
- Specified by:
bulkCacheRoles
in interfaceEntityCacheWorker
-
bulkCacheMembers
- Specified by:
bulkCacheMembers
in interfaceEntityCacheWorker
-
bulkCacheEmoji
- Specified by:
bulkCacheEmoji
in interfaceEntityCacheWorker
-
bulkCachePresences
- Specified by:
bulkCachePresences
in interfaceEntityCacheWorker
-
bulkCacheVoiceStates
public void bulkCacheVoiceStates(@Nonnegative int shardId, @Nonnull Collection<VoiceState> voiceStates) - Specified by:
bulkCacheVoiceStates
in interfaceEntityCacheWorker
-
bulkCacheThreadMembers
public void bulkCacheThreadMembers(int shardId, @Nonnull Collection<ThreadChannel.ThreadMember> threadMembers) - Specified by:
bulkCacheThreadMembers
in interfaceEntityCacheWorker
-
invalidateShard
public void invalidateShard(int id) - Specified by:
invalidateShard
in interfaceEntityCacheWorker
-
guilds
- Specified by:
guilds
in interfaceEntityCache
- Returns:
- A view of the current guild cache. Updates to the cache will update this view.
-
members
Description copied from interface:EntityCache
Get all members for the guild with the given ID.- Specified by:
members
in interfaceEntityCache
- Parameters:
guildId
- The ID of the guild to fetch members for.- Returns:
- A view of the current member cache of the guild. Updates to the cache will update this view.
-
members
Description copied from interface:EntityCache
Get all members cached in this entity cache.- Specified by:
members
in interfaceEntityCache
- Returns:
- A view of all the current member caches. Updates to the caches or additions/removals (of guilds) will update this view.
-
roles
Description copied from interface:EntityCache
Get all roles for the guild with the given ID.- Specified by:
roles
in interfaceEntityCache
- Parameters:
guildId
- The ID of the guild to fetch roles for.- Returns:
- A view of the current role cache of the guild. Updates to the cache will update this view.
-
roles
Description copied from interface:EntityCache
Get all roles cached in this entity cache.- Specified by:
roles
in interfaceEntityCache
- Returns:
- A view of all the current role caches. Updates to the caches or additions/removals (of guilds) will update this view.
-
channels
Description copied from interface:EntityCache
Get all channels for the guild with the given ID.- Specified by:
channels
in interfaceEntityCache
- Parameters:
guildId
- The ID of the guild to fetch channels for.- Returns:
- A view of the current channel cache of the guild. Updates to the cache will update this view.
-
channels
Description copied from interface:EntityCache
Get all guild channels cached in this entity cache.- Specified by:
channels
in interfaceEntityCache
- Returns:
- A view of all the current guild channel caches. Updates to the caches or additions/removals (of guilds) will update this view.
-
emojis
Description copied from interface:EntityCache
Get all custom emojis for the guild with the given ID.- Specified by:
emojis
in interfaceEntityCache
- Parameters:
guildId
- The ID of the guild to fetch custom emojis for.- Returns:
- A view of the current emoji cache of the guild. Updates to the cache will update this view.
-
emojis
Description copied from interface:EntityCache
Get all emojis cached in this entity cache.- Specified by:
emojis
in interfaceEntityCache
- Returns:
- A view of all the current emoji caches. Updates to the caches or additions/removals (of guilds) will update this view.
-
threadMembers
- Specified by:
threadMembers
in interfaceEntityCache
-
voiceStates
Description copied from interface:EntityCache
Get all voice states for the guild with the given ID.- Specified by:
voiceStates
in interfaceEntityCache
- Parameters:
guildId
- The ID of the guild to fetch voice states for.- Returns:
- A view of the current voice state cache of the guild. Updates to the cache will update this view.
-
voiceStates
Description copied from interface:EntityCache
Get all voice states for the entire bot.- Specified by:
voiceStates
in interfaceEntityCache
- Returns:
- A view of all the current voice state caches. Updates to the caches or additions/removals (of guilds) will update this view.
-
catnip
- Specified by:
catnip
in interfaceEntityCacheWorker
-
catnip
-