View Source Nostrum.Cache.MessageCache.Mnesia (Nostrum v0.10.0)
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 documentation for more information.
To retrieve the table name used by this cache, use table/0
.
By default, the cache will store up to 10_000
messages,
and will evict the 100
oldest messages when the limit is reached.
The reason for the eviction count is that with mnesia it is more efficient to find X oldest records and delete them all at once than to find the oldest record and delete it each time a new record is added.
The Mnesia cache supports the following configuration options:
size_limit
: The maximum number of messages to store in the cache. default:10_000
eviction_count
: The number of messages to evict when the cache is full. default:100
table_name
: The name of the Mnesia table to use for the cache. default::nostrum_messages
compressed
: Whether to use compressed in memory storage for the table. default:false
type
: Sets the type of Mnesia table created to cache messages. Can be either:set
or:ordered_set
, by choosing:ordered_set
the eviction of the oldest messages will be more efficient, however it means that the table cannot be changed to only store its contents on disk later. default::ordered_set
To change this configuration, you can add the following to your
config.exs
:
config :nostrum,
caches: %{
messages: {Nostrum.Cache.MessageCache.Mnesia,
size_limit: 1000, eviction_count: 50,
table_name: :my_custom_messages_table_name,
compressed: true, type: :set}
}
You can also change the table name used by the cache by setting the
table_name
field in the configuration for the messages
cache.
Summary
Functions
Removes and returns a list of messages from the cache. Messages not found in the cache will not be included in the returned list.
Removes all messages for a channel which was deleted.
Returns a specification to start this module under a supervisor.
Clear any objects in the cache.
Adds a message to the cache.
Removes a message from the cache.
Retrieve a single message from the cache by id.
Retrieve a list of messages from the cache with a given author ID, optionally after a given date, and before a given date.
Retrieve a list of messages from the cache with a given channel ID, optionally after a given date, and before a given date.
Retrieve a list of messages from the cache with a given channel ID and author ID, optionally after a given date, and before a given date.
Set up the cache's Mnesia table.
Return a QLC query handle for the cache for read operations.
Start the supervisor.
Retrieve the Mnesia table name used for the cache.
Drop the table used for caching.
Updates a message in the cache.
Functions
@spec bulk_delete(Nostrum.Struct.Channel.id(), [Nostrum.Struct.Message.id()]) :: [ Nostrum.Struct.Message.t() ]
Removes and returns a list of messages from the cache. Messages not found in the cache will not be included in the returned list.
@spec channel_delete(Nostrum.Struct.Channel.id()) :: :ok
Removes all messages for a channel which was deleted.
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec clear() :: :ok
Clear any objects in the cache.
@spec create(map()) :: Nostrum.Struct.Message.t()
Adds a message to the cache.
@spec delete(Nostrum.Struct.Channel.id(), Nostrum.Struct.Message.id()) :: Nostrum.Struct.Message.t() | nil
Removes a message from the cache.
@spec get(Nostrum.Struct.Message.id()) :: {:ok, Nostrum.Struct.Message.t()} | {:error, :not_found}
Retrieve a single message from the cache by id.
get_by_author(author_id, after_timestamp \\ 0, before_timestamp \\ :infinity)
View Source (since 0.10.0)@spec get_by_author( Nostrum.Struct.User.id(), Nostrum.Cache.MessageCache.timestamp_like(), Nostrum.Cache.MessageCache.timestamp_like() | :infinity ) :: [Nostrum.Struct.Message.t()]
Retrieve a list of messages from the cache with a given author ID, optionally after a given date, and before a given date.
Integers are treated as snowflakes, and the atom :infinity
when given
as a before date will be treated as the maximum possible date.
get_by_channel(channel_id, after_timestamp \\ 0, before_timestamp \\ :infinity)
View Source (since 0.10.0)@spec get_by_channel( Nostrum.Struct.Channel.id(), Nostrum.Cache.MessageCache.timestamp_like(), Nostrum.Cache.MessageCache.timestamp_like() | :infinity ) :: [Nostrum.Struct.Message.t()]
Retrieve a list of messages from the cache with a given channel ID, optionally after a given date, and before a given date.
get_by_channel_and_author(channel_id, author_id, after_timestamp \\ 0, before_timestamp \\ :infinity)
View Source (since 0.10.0)@spec get_by_channel_and_author( Nostrum.Struct.Channel.id(), Nostrum.Struct.User.id(), Nostrum.Cache.MessageCache.timestamp_like(), Nostrum.Cache.MessageCache.timestamp_like() | :infinity ) :: [Nostrum.Struct.Message.t()]
Retrieve a list of messages from the cache with a given channel ID and author ID, optionally after a given date, and before a given date.
Set up the cache's Mnesia table.
@spec query_handle() :: :qlc.query_handle()
Return a QLC query handle for the cache for read operations.
Start the supervisor.
@spec table() :: atom()
Retrieve the Mnesia table name used for the cache.
@spec teardown() :: {:atomic, :ok} | {:aborted, term()}
Drop the table used for caching.
@spec update(map()) :: {old_message :: Nostrum.Struct.Message.t() | nil, updated_message :: Nostrum.Struct.Message.t()}
Updates a message in the cache.