Raxol.Agent.Cache.Ets (Raxol Agent v2.6.0)

Copy Markdown View Source

ETS-backed Raxol.Agent.Cache adapter.

Stores entries in a named ETS table created lazily on the first call. The table is :public and :set keyed on the user's term; values are wrapped with their absolute expiry timestamp so get/2 can decide stale-vs-fresh with a single comparison.

Config

%{table: :my_agent_cache}

Defaults to :raxol_agent_cache when the :table key is absent. Two agents sharing the same table name share its entries; isolate per-agent by passing distinct table names.

Lifetime

The table lives for the duration of the BEAM. It is not supervised and does not survive Application.stop/1. Use Raxol.Agent.Cache.Postgrex when cache entries must outlive the BEAM or be shared across nodes.

Lazy expiry

get/2 checks the wrapped expiry against DateTime.utc_now/0. A stale entry returns :miss and is removed from the table in the same call. No background sweeper; expired-but-unread entries occupy table memory until either get/2 checks them or flush/1 clears the table.

Not for very-high-throughput shared writes

ETS handles concurrent reads + writes fine, but two writers to the same key racing through put/4 will both succeed; the second silently overwrites the first. The Saver-style append-only contract does not apply to caches; last-write-wins is the intended cache semantics.

Summary

Functions

Ensure the configured ETS table exists. Idempotent.

Functions

ensure_table(config)

@spec ensure_table(map()) :: atom()

Ensure the configured ETS table exists. Idempotent.