Package com.mewna.catnip.cache
Class CustomizableEntityCache
java.lang.Object
com.mewna.catnip.cache.CustomizableEntityCache
- All Implemented Interfaces:
EntityCache
,EntityCacheWorker
- Direct Known Subclasses:
NoopEntityCache
A customizable entity cache is basically just what it sounds like - a cache
whose behaviour is ENTIRELY meant to be customized. By default, this cache
will return
noop caches
and futures completed with
null
. If you want to write a custom partial cache, this is probably
the best place to start so that you don't have lots of empty method bodies.- Since:
- 3/7/19.
- Author:
- amy
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.mewna.catnip.cache.EntityCacheWorker
EntityCacheWorker.CachedEntityState
-
Field Summary
-
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) 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.channels()
Get all guild channels cached in this entity cache.channels
(long guildId) Get all channels for the guild with the given ID.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.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.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.members()
Get all members cached in this entity cache.members
(long guildId) Get all members for the guild with the given ID.io.reactivex.rxjava3.core.Maybe<Presence>
presence
(long id) Get the presence for the user with the specified ID.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.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()
io.reactivex.rxjava3.core.Maybe<ThreadChannel.ThreadMember>
threadMember
(long id) io.reactivex.rxjava3.core.Maybe<ThreadChannel.ThreadMember>
threadMember
(String 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.users()
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.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, role, roles, user, voiceState, voiceStates
Methods inherited from interface com.mewna.catnip.cache.EntityCacheWorker
canProvidePreviousState
-
Field Details
-
catnip
-
-
Constructor Details
-
CustomizableEntityCache
public CustomizableEntityCache()
-
-
Method Details
-
catnip
- Specified by:
catnip
in interfaceEntityCacheWorker
-
updateCache
@Nonnull public io.reactivex.rxjava3.core.Completable updateCache(@Nonnull String eventType, 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
- 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
-
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.
-
guilds
- Specified by:
guilds
in interfaceEntityCache
- Returns:
- A view of the current guild cache. Updates to the cache will update this view.
-
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.
-
users
- Specified by:
users
in interfaceEntityCache
- Returns:
- A view of the current user cache. Updates to the cache will update this view.
-
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.
-
presences
- Specified by:
presences
in interfaceEntityCache
- Returns:
- A view of the current presence cache. Updates to the cache will update this view.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
selfUser
- Specified by:
selfUser
in interfaceEntityCache
- Returns:
- The currently-logged-in user. May be
null
if no shards have logged in.
-
threadMember
@Nonnull public io.reactivex.rxjava3.core.Maybe<ThreadChannel.ThreadMember> threadMember(@Nonnull String id) - Specified by:
threadMember
in interfaceEntityCache
-
threadMember
- Specified by:
threadMember
in interfaceEntityCache
-
threadMembers
- Specified by:
threadMembers
in interfaceEntityCache
-