Package discord4j.core.retriever
Interface EntityRetrievalStrategy
- All Superinterfaces:
Function<GatewayDiscordClient,
EntityRetriever>
- 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 EntityRetrievalStrategy
extends Function<GatewayDiscordClient,EntityRetriever>
Defines the entity retrieval strategy to use for a given
GatewayDiscordClient
.
This class pre-defines some factories according to its main modes of operations:
STORE
to exclusively fetch data from the Gateway state cache.REST
to fetch data directly from the REST API.STORE_FALLBACK_REST
to attempt fetching from the state cache, and if not successful, fetch from REST. This the default mode.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final EntityRetrievalStrategy
Strategy that consists of retrieving entities from REST API.static final EntityRetrievalStrategy
Strategy that consists of retrieving entities from the Gateway state cache.static final EntityRetrievalStrategy
Strategy that consists of retrieving entities from stores first, then hit the REST API if not found. -
Method Summary
-
Field Details
-
STORE
Strategy that consists of retrieving entities from the Gateway state cache. Avoids making REST API requests in case the object is not present in the cache. If you want to perform actions when a requested entity is missing, use operators such asMono.switchIfEmpty(Mono)
.Note that using this strategy can have some unintended consequences like being unable to fetch some entities not cached by the gateway, for example, private channels. If that is your use case, locally apply a method like
GatewayDiscordClient.withRetrievalStrategy(EntityRetrievalStrategy)
usingREST
. -
REST
Strategy that consists of retrieving entities from REST API. -
STORE_FALLBACK_REST
Strategy that consists of retrieving entities from stores first, then hit the REST API if not found.
-