# `Jido.Messaging.Deduper`
[🔗](https://github.com/agentjido/jido_messaging/blob/v1.0.0/lib/jido_messaging/deduper.ex#L1)

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

# `key`

```elixir
@type key() :: term()
```

# `t`

```elixir
@type t() :: %Jido.Messaging.Deduper{
  instance_module: any(),
  table: any(),
  ttl_ms: integer()
}
```

# `check_and_mark`

```elixir
@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.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `clear`

```elixir
@spec clear(module()) :: :ok
```

Clear all dedupe keys (useful for testing).

# `count`

```elixir
@spec count(module()) :: non_neg_integer()
```

Get the count of tracked keys.

# `mark_seen`

```elixir
@spec mark_seen(module(), key(), non_neg_integer() | nil) :: :ok
```

Manually mark a key as seen.

# `schema`

Returns the Zoi schema

# `seen?`

```elixir
@spec seen?(module(), key()) :: boolean()
```

Check if a key has been seen (without marking).

# `start_link`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
