diff --git a/lib/nostrum/cache/cache_supervisor.ex b/lib/nostrum/cache/cache_supervisor.ex index 841f56e4f..04cdbb771 100644 --- a/lib/nostrum/cache/cache_supervisor.ex +++ b/lib/nostrum/cache/cache_supervisor.ex @@ -24,6 +24,7 @@ defmodule Nostrum.Cache.CacheSupervisor do Nostrum.Cache.ChannelGuildMapping, Nostrum.Cache.GuildCache, Nostrum.Cache.MemberCache, + Nostrum.Cache.MessageCache, Nostrum.Cache.UserCache, Nostrum.Cache.PresenceCache ] diff --git a/lib/nostrum/cache/message_cache.ex b/lib/nostrum/cache/message_cache.ex index 0ac796553..7888cdbc9 100644 --- a/lib/nostrum/cache/message_cache.ex +++ b/lib/nostrum/cache/message_cache.ex @@ -40,7 +40,7 @@ defmodule Nostrum.Cache.MessageCache do # callbacks @doc """ - Retrieve a single `Nostrum.Struct.Message` from the cache by channel id and message id. + Retrieve a single `Nostrum.Struct.Message` from the cache by its ID. """ @callback get(Message.id()) :: {:ok, Message.t()} | {:error, :not_found} @@ -68,19 +68,19 @@ defmodule Nostrum.Cache.MessageCache do @callback delete(Channel.id(), Message.id()) :: Message.t() | nil @doc """ - Deletes multiple messages from the cache, any message id's given + Deletes multiple messages from the cache, any message IDs given will always be for the same channel. - Returns a list of the deleted messages, - if a message was not found in the cache, it will - still be included in the returned list with - only the id and channel_id set. + Returns a list of the deleted messages. + Note that if a message was not found in the cache, it will + not be included in the returned list. """ @callback bulk_delete(Channel.id(), [Message.id()]) :: [Message.t()] @doc """ - Callback for when a channel is deleted - any messages in the cache for that channel should be removed. + Called when a channel is deleted. + + Any messages in the cache for the channel should be removed. """ @callback channel_delete(Channel.id()) :: :ok diff --git a/lib/nostrum/cache/message_cache/mnesia.ex b/lib/nostrum/cache/message_cache/mnesia.ex index 436a3d68f..59a7c7f52 100644 --- a/lib/nostrum/cache/message_cache/mnesia.ex +++ b/lib/nostrum/cache/message_cache/mnesia.ex @@ -3,11 +3,7 @@ if Code.ensure_loaded?(:mnesia) do @moduledoc """ An Mnesia-based cache for messages. - Please note that this module is only compiled if Mnesia is available on - your system. See the Mnesia section of the [State](functionality/state.md) - documentation for more information. - - To retrieve the table name used by this cache, use `table/0`. + #{Nostrum.Cache.Base.mnesia_note()} By default, the cache will store up to 10,000 messages. To change this limit, add the `:message_cache_size_limit` key to the `:caches` diff --git a/src/nostrum_message_cache_qlc.erl b/src/nostrum_message_cache_qlc.erl index 2b8aad568..6fab0bfdb 100644 --- a/src/nostrum_message_cache_qlc.erl +++ b/src/nostrum_message_cache_qlc.erl @@ -38,7 +38,7 @@ by_channel(RequestedChannelId, Cache) -> ChannelId =:= RequestedChannelId]), qlc:keysort(1, Q1). -% lookup the ids of all cached messages for a given channel. +% lookup the IDs of all cached messages for a given channel. -spec all_message_ids_in_channel('Elixir.Nostrum.Struct.Channel':id(), module()) -> qlc:query_handle(). all_message_ids_in_channel(RequestedChannelId, ?MNESIA_CACHE) -> qlc:q([MessageId || {_Tag, MessageId, ChannelId, _, _Message} <- ?MNESIA_CACHE:query_handle(), @@ -103,7 +103,7 @@ sorted_by_age_with_limit(Cache, Limit) -> sort_with_limit(Q1, Limit) -> Fn = fun (MessageId, {Count1, Set1, Largest1}) -> - if (MessageId < Largest1) and (Count1 >= Limit) -> + if (MessageId < Largest1) andalso (Count1 >= Limit) -> Set2 = gb_sets:delete(Largest1, Set1), Set3 = gb_sets:insert(MessageId, Set2), Largest2 = gb_sets:largest(Set3),