Central message deduplication using ETS with TTL.
Prevents duplicate processing of inbound messages by tracking seen message keys. Keys expire after a configurable TTL and are periodically swept.
Usage
# Check and mark atomically (returns :new or :duplicate)
case Deduper.check_and_mark(MyApp.Messaging, {:telegram, "inst_123", 12345}) do
:new -> process_message()
:duplicate -> :ok
end
Summary
Functions
Check if a key has been seen before and mark it as seen if new.
Returns a specification to start this module under a supervisor.
Clear all dedupe keys (useful for testing).
Get the count of tracked keys.
Manually mark a key as seen.
Returns the Zoi schema
Check if a key has been seen (without marking).
Types
Functions
@spec check_and_mark(module(), key(), non_neg_integer() | nil) :: :new | :duplicate
Check if a key has been seen before and mark it as seen if new.
Returns :new if the key is new (and marks it), :duplicate if already seen.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear(module()) :: :ok
Clear all dedupe keys (useful for testing).
@spec count(module()) :: non_neg_integer()
Get the count of tracked keys.
@spec mark_seen(module(), key(), non_neg_integer() | nil) :: :ok
Manually mark a key as seen.
Returns the Zoi schema
Check if a key has been seen (without marking).