LemonCore.Dedupe.Ets (lemon_core v0.1.0)

View Source

Simple TTL-based deduplication backed by ETS.

Stores {key, ts_ms} entries in an ETS :set table, where ts_ms is the monotonic time (ms) when the key was marked.

TTL semantics:

  • A key is considered "seen" if now_ms - ts_ms <= ttl_ms.
  • Expired entries are deleted on access (and can also be cleaned in bulk).

Summary

Functions

Combined check + mark operation.

Best-effort cleanup of entries older than ttl_ms.

Ensure the ETS table exists.

Mark a key as seen.

Check whether a key has been seen within ttl_ms.

Types

key()

@type key() :: term()

table()

@type table() :: :ets.tid() | atom()

Functions

check_and_mark(table, key, ttl_ms)

@spec check_and_mark(table(), key(), integer()) :: :seen | :new

Combined check + mark operation.

Returns :seen if the key is currently within TTL, otherwise marks it and returns :new.

cleanup_expired(table, ttl_ms)

@spec cleanup_expired(table(), integer()) :: non_neg_integer()

Best-effort cleanup of entries older than ttl_ms.

init(table, opts \\ [])

@spec init(
  table(),
  keyword()
) :: :ok

Ensure the ETS table exists.

If table is an atom, a named table is created.

mark(table, key)

@spec mark(table(), key()) :: :ok

Mark a key as seen.

seen?(table, key, ttl_ms)

@spec seen?(table(), key(), integer()) :: boolean()

Check whether a key has been seen within ttl_ms.

Deletes expired entries.