View Source Nostrum.Cache.UserCache behaviour (Nostrum v0.6.1)

Cache behaviour & dispatcher for users.

You can call the functions provided by this module independent of which cache is configured, and it will dispatch to the configured cache implementation.

By default, Elixir.Nostrum.Cache.UserCache.ETS will be used for caching users. You can override this in the :caches option of the :nostrum application by setting the :users field to a different module implementing the behaviour defined by this module.

See the documentation for the Nostrum.Cache.GuildCache module for more details.

Link to this section Summary

Callbacks

Bulk add multiple users to the cache at once.

Add a new user to the cache based on the Discord Gateway payload.

Delete a user by ID.

Retrieves a user from the cache by id.

Update a user in the cache based on payload sent via the Gateway.

Link to this section Callbacks

Link to this callback

bulk_create(user_payloads)

View Source

Specs

bulk_create(user_payloads :: Enum.t()) :: :ok

Bulk add multiple users to the cache at once.

Returns :ok.

Specs

create(payload :: map()) :: Nostrum.Struct.User.t()

Add a new user to the cache based on the Discord Gateway payload.

Returns a Nostrum.Struct.User.t/0 struct representing the created user.

Specs

delete(snowflake :: Nostrum.Struct.User.id()) :: :noop | Nostrum.Struct.User.t()

Delete a user by ID.

Returns the deleted user if present in the cache, or :noop if the user was not cached.

Specs

get(id :: Nostrum.Struct.User.id()) ::
  {:ok, Nostrum.Struct.User.t()} | {:error, atom()}

Retrieves a user from the cache by id.

If successful, returns {:ok, user}. Otherwise, returns {:error, reason}.

Example

case Nostrum.Cache.UserCache.get(1111222233334444) do
  {:ok, user} ->
    "We found " <> user.username
  {:error, _reason} ->
    "No es bueno"
end

Specs

update(payload :: map()) ::
  :noop | {Nostrum.Struct.User.t(), Nostrum.Struct.User.t()}

Update a user in the cache based on payload sent via the Gateway.

Returns :noop if the user has not been updated in the cache, or {old_user, new_user} is the user has been written to the cache.

Link to this section Functions