Nosedrum.MessageCache.Agent (nosedrum v0.6.0) View Source

An Agent-based message cache.

Note that using this cache across your entire bot can easily lead to the cache becoming a bottleneck, since an agent is a single process. Instead, you might want to use this cache across several smaller guilds to avoid overloading a single process with events from multiple guilds.

Usage

defmodule MyBot.Application do
  use Application

  def start(type, args) do
    children = [
      %{
        id: MessageCache,
        start: {Nosedrum.MessageCache.Agent, :start_link, [[name: Nosedrum.MessageCache.Agent]]}
      }
    ]
  end
end

If using multiple instances of this agent, you can pass the agent process reference as the last argument to the individual functions that this implementation provides. By default, this uses Nosedrum.MessageCache.Agent as the agent reference, requiring you to specify the name: in your application callback.

Configuration

By default, the cache keeps up to 200 messages in the cache per guild. To configure this, you can pass the limit: option as an argument to the process, such as:

defmodule MyBot.Application do
  use Application

  def start(type, args) do
    children = [
      %{
        id: MessageCache,
        start: {Nosedrum.MessageCache.Agent, :start_link, [[name: Nosedrum.MessageCache.Agent, limit: 50]]}
      }
    ]
  end
end

This will ensure that no more than 50 messages are kept in cache per guild.