Nosedrum.MessageCache.ETS (nosedrum v0.6.0) View Source
An ETS-table based message cache.
This module does not implement any cache expiration: by default, the
table fills up infinitely. One possibility of keeping messages under control
would be to delete all messages sent before a certain date. Since the key
of table entries are message IDs, you can use
:ets.select_delete/2
to accomplish this. For example, to delete all messages older than one day,
you could use the following construct:
now = DateTime.utc_now()
one_day_ago = DateTime.add(now, -1, :day)
snowflake = Nostrum.Snowflake.from_datetime!(one_day_ago)
match_spec = [{{:"$1", :_, :_, :_, :_}, [{:<, :"$1", snowflake}], [true]}]
:ets.select_delete(:nosedrum_message_cache, match_spec)
For deleting in different ways such as by guild ID, use
:ets.fun2ms/1
to generate match
specifications from functions.
You can use the GenServer.call(cache_process, :tid)
to obtain the internal
table ID when not using a named table.
Link to this section Summary
Functions
See Nosedrum.MessageCache.consume/2
.
Returns the result of :ets.insert
.
Initialize the ETS message cache.
See Nosedrum.MessageCache.update/2
.
Returns the result of :ets.insert/2
.
Link to this section Functions
See Nosedrum.MessageCache.consume/2
.
Returns the result of :ets.insert
.
start_link(table_name \\ :nosedrum_message_cache, table_options \\ [{:read_concurrency, true}, {:write_concurrency, true}, :ordered_set, :public, :named_table], gen_options)
View SourceInitialize the ETS message cache.
By default, the table used for storing messages is a named table with
the name :nosedrum_message_cache
. The table reference is stored internally
as the state of this process, the public-facing API functions default
to using the table name to access the module.
See Nosedrum.MessageCache.update/2
.
Returns the result of :ets.insert/2
.