Package org.javacord.api.entity
Interface UpdatableFromCache<T extends DiscordEntity>
-
- All Superinterfaces:
Updatable<T>
- All Known Subinterfaces:
Channel,ChannelCategory,CustomEmoji,KnownCustomEmoji,Message,PrivateChannel,RegularServerChannel,Role,Server,ServerChannel,ServerForumChannel,ServerStageVoiceChannel,ServerTextChannel,ServerThreadChannel,ServerVoiceChannel,TextChannel,UnknownRegularServerChannel,UnknownServerChannel,User,VoiceChannel
public interface UpdatableFromCache<T extends DiscordEntity> extends Updatable<T>
This class represents an entity which is updatable from cache.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.Optional<T>getCurrentCachedInstance()Gets an updated instance of this entity from the cache.default java.util.concurrent.CompletableFuture<T>getLatestInstance()Gets an updated instance of this entity from the cache or from Discord directly.
-
-
-
Method Detail
-
getCurrentCachedInstance
java.util.Optional<T> getCurrentCachedInstance()
Gets an updated instance of this entity from the cache. This is for example necessary if an instance got invalid by a reconnect to Discord which invalidates all existing instances which means they do not get any further updates from Discord applied. Due to that, references to instances should usually not be held for an extended period of time. If they are, this method can be used to retrieve the current instance from the cache, that gets updates from Discord, in case this one was invalidated.This method returns the currently cached entity, or an empty
Optionalif the entity is not cached any longer, for example because it was deleted or the message was thrown out of the cache.- Returns:
- The current cached instance.
-
getLatestInstance
default java.util.concurrent.CompletableFuture<T> getLatestInstance()
Description copied from interface:UpdatableGets an updated instance of this entity from the cache or from Discord directly. This is for example necessary if an instance got invalid by a reconnect to Discord which invalidates all existing instances which means they do not get any further updates from Discord applied. Due to that, references to instances should usually not be held for an extended period of time. If they are, this method can be used to retrieve the current instance from the cache if present or from Discord directly.This method returns the currently cached entity if present, or request the entity from Discord if it is not cached or not permanently cached. If the entity is a fully cached entity and is not in the cache any longer, for example because it was deleted or the message was thrown out of the cache, the
CompletableFuturecompletes exceptionally with aNoSuchElementException. If a request to Discord is made, the according remote call exception will be used to complete theCompletableFutureexceptionally.- Specified by:
getLatestInstancein interfaceUpdatable<T extends DiscordEntity>- Returns:
- The current cached instance.
-
-