Class CustomizableEntityCache

java.lang.Object
com.mewna.catnip.cache.CustomizableEntityCache
All Implemented Interfaces:
EntityCache, EntityCacheWorker
Direct Known Subclasses:
NoopEntityCache

public abstract class CustomizableEntityCache extends Object implements EntityCacheWorker
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
  • Field Details

    • catnip

      protected Catnip catnip
  • Constructor Details

    • CustomizableEntityCache

      public CustomizableEntityCache()
  • Method Details

    • catnip

      @OverridingMethodsMustInvokeSuper @Nonnull public EntityCache catnip(@Nonnull Catnip catnip)
      Specified by:
      catnip in interface EntityCacheWorker
    • 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 interface EntityCacheWorker
      Parameters:
      eventType - Type of the event.
      payload - Data payload contained in the event
      Returns:
      Itself.
    • bulkCacheUsers

      public void bulkCacheUsers(int shardId, @Nonnull Collection<User> users)
      Specified by:
      bulkCacheUsers in interface EntityCacheWorker
    • bulkCacheChannels

      public void bulkCacheChannels(int shardId, @Nonnull Collection<GuildChannel> channels)
      Specified by:
      bulkCacheChannels in interface EntityCacheWorker
    • bulkCacheRoles

      public void bulkCacheRoles(int shardId, @Nonnull Collection<Role> roles)
      Specified by:
      bulkCacheRoles in interface EntityCacheWorker
    • bulkCacheMembers

      public void bulkCacheMembers(int shardId, @Nonnull Collection<Member> members)
      Specified by:
      bulkCacheMembers in interface EntityCacheWorker
    • bulkCacheEmoji

      public void bulkCacheEmoji(int shardId, @Nonnull Collection<Emoji.CustomEmoji> emoji)
      Specified by:
      bulkCacheEmoji in interface EntityCacheWorker
    • bulkCachePresences

      public void bulkCachePresences(int shardId, @Nonnull Map<String,Presence> presences)
      Specified by:
      bulkCachePresences in interface EntityCacheWorker
    • bulkCacheVoiceStates

      public void bulkCacheVoiceStates(int shardId, @Nonnull Collection<VoiceState> voiceStates)
      Specified by:
      bulkCacheVoiceStates in interface EntityCacheWorker
    • bulkCacheThreadMembers

      public void bulkCacheThreadMembers(int shardId, @Nonnull Collection<ThreadChannel.ThreadMember> threadMembers)
      Specified by:
      bulkCacheThreadMembers in interface EntityCacheWorker
    • invalidateShard

      public void invalidateShard(int id)
      Specified by:
      invalidateShard in interface EntityCacheWorker
    • guild

      @Nonnull public io.reactivex.rxjava3.core.Maybe<Guild> guild(long id)
      Description copied from interface: EntityCache
      Get the guild with the specified ID. May be null.
      Specified by:
      guild in interface EntityCache
      Parameters:
      id - The ID of the guild to fetch.
      Returns:
      The guild, or null if it isn't cached.
    • guilds

      @Nonnull public NamedCacheView<Guild> guilds()
      Specified by:
      guilds in interface EntityCache
      Returns:
      A view of the current guild cache. Updates to the cache will update this view.
    • user

      @Nonnull public io.reactivex.rxjava3.core.Maybe<User> user(long id)
      Description copied from interface: EntityCache
      Get the user with the specified ID. May be null.
      Specified by:
      user in interface EntityCache
      Parameters:
      id - The ID of the user to fetch.
      Returns:
      The user, or null if it isn't cached.
    • users

      @Nonnull public NamedCacheView<User> users()
      Specified by:
      users in interface EntityCache
      Returns:
      A view of the current user cache. Updates to the cache will update this view.
    • presence

      @Nonnull public io.reactivex.rxjava3.core.Maybe<Presence> presence(long id)
      Description copied from interface: EntityCache
      Get the presence for the user with the specified ID. May be null.
      Specified by:
      presence in interface EntityCache
      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

      @Nonnull public CacheView<Presence> presences()
      Specified by:
      presences in interface EntityCache
      Returns:
      A view of the current presence cache. Updates to the cache will update this view.
    • member

      @Nonnull public io.reactivex.rxjava3.core.Maybe<Member> member(long guildId, long id)
      Description copied from interface: EntityCache
      Get the member with the given ID from the guild with the given ID. May be null.
      Specified by:
      member in interface EntityCache
      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

      @Nonnull public NamedCacheView<Member> members(long guildId)
      Description copied from interface: EntityCache
      Get all members for the guild with the given ID.
      Specified by:
      members in interface EntityCache
      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

      @Nonnull public NamedCacheView<Member> members()
      Description copied from interface: EntityCache
      Get all members cached in this entity cache.
      Specified by:
      members in interface EntityCache
      Returns:
      A view of all the current member caches. Updates to the caches or additions/removals (of guilds) will update this view.
    • role

      @Nonnull public io.reactivex.rxjava3.core.Maybe<Role> role(long guildId, long id)
      Description copied from interface: EntityCache
      Get the role with the given ID from the guild with the given ID. May be null.
      Specified by:
      role in interface EntityCache
      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

      @Nonnull public NamedCacheView<Role> roles(long guildId)
      Description copied from interface: EntityCache
      Get all roles for the guild with the given ID.
      Specified by:
      roles in interface EntityCache
      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

      @Nonnull public NamedCacheView<Role> roles()
      Description copied from interface: EntityCache
      Get all roles cached in this entity cache.
      Specified by:
      roles in interface EntityCache
      Returns:
      A view of all the current role caches. Updates to the caches or additions/removals (of guilds) will update this view.
    • channel

      @Nonnull public io.reactivex.rxjava3.core.Maybe<GuildChannel> channel(long guildId, long id)
      Description copied from interface: EntityCache
      Get the channel with the given ID from the guild with the given ID. May be null.
      Specified by:
      channel in interface EntityCache
      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

      @Nonnull public NamedCacheView<GuildChannel> channels(long guildId)
      Description copied from interface: EntityCache
      Get all channels for the guild with the given ID.
      Specified by:
      channels in interface EntityCache
      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

      @Nonnull public NamedCacheView<GuildChannel> channels()
      Description copied from interface: EntityCache
      Get all guild channels cached in this entity cache.
      Specified by:
      channels in interface EntityCache
      Returns:
      A view of all the current guild channel caches. Updates to the caches or additions/removals (of guilds) will update this view.
    • emoji

      @Nonnull public io.reactivex.rxjava3.core.Maybe<Emoji.CustomEmoji> emoji(long guildId, long id)
      Description copied from interface: EntityCache
      Get the custom emojis with the given ID from the guild with the given ID. May be null,
      Specified by:
      emoji in interface EntityCache
      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

      @Nonnull public NamedCacheView<Emoji.CustomEmoji> emojis(long guildId)
      Description copied from interface: EntityCache
      Get all custom emojis for the guild with the given ID.
      Specified by:
      emojis in interface EntityCache
      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

      @Nonnull public NamedCacheView<Emoji.CustomEmoji> emojis()
      Description copied from interface: EntityCache
      Get all emojis cached in this entity cache.
      Specified by:
      emojis in interface EntityCache
      Returns:
      A view of all the current emoji caches. Updates to the caches or additions/removals (of guilds) will update this view.
    • voiceState

      @Nonnull public io.reactivex.rxjava3.core.Maybe<VoiceState> voiceState(long guildId, long id)
      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 be null.
      Specified by:
      voiceState in interface EntityCache
      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

      @Nonnull public CacheView<VoiceState> voiceStates(long guildId)
      Description copied from interface: EntityCache
      Get all voice states for the guild with the given ID.
      Specified by:
      voiceStates in interface EntityCache
      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

      @Nonnull public CacheView<VoiceState> voiceStates()
      Description copied from interface: EntityCache
      Get all voice states for the entire bot.
      Specified by:
      voiceStates in interface EntityCache
      Returns:
      A view of all the current voice state caches. Updates to the caches or additions/removals (of guilds) will update this view.
    • selfUser

      @Nonnull public io.reactivex.rxjava3.core.Maybe<User> selfUser()
      Specified by:
      selfUser in interface EntityCache
      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 interface EntityCache
    • threadMember

      @Nonnull public io.reactivex.rxjava3.core.Maybe<ThreadChannel.ThreadMember> threadMember(long id)
      Specified by:
      threadMember in interface EntityCache
    • threadMembers

      @Nonnull public CacheView<ThreadChannel.ThreadMember> threadMembers()
      Specified by:
      threadMembers in interface EntityCache