Kantoor. Bodies
(Kantoor v1.0.0)
Bounded cache of raw message bodies. Karta stays the system of record; this table only saves a round trip for mail that was pushed with its bytes (and holds drafts, which Karta never sees).
put/3stores zlib-compressed bytes (ingest, send, draft save);get/1returns a hit and refresheslast_read_at;fetch/1is read-through: on a miss it asksKantoor.Karta.Clientand re-caches the result;sweep/1evicts least-recently-read, unpinned bodies until the cache fits the budget (Kantoor.Bodies.Sweeperruns it periodically).
Config (config :kantoor, Kantoor.Bodies): :budget_bytes (default 2 GiB, the
compressed bytes kept per instance), :sweep_interval_ms (default 60_000, or
:infinity to disable the timer).
Summary
Functions
The configured budget in compressed bytes.
Drops the cached body of a message (e.g. after expunge).
Read-through fetch. A miss asks Karta for the raw bytes and caches them.
Returns {:error, :unavailable} when Karta cannot deliver; never raises.
A cache hit as {:ok, raw} (refreshing its LRU time), else :miss.
Caches raw for message_id. Never raises: a failure (or a body that alone
exceeds the budget) just means the next read goes to Karta.
Options: pinned: true for bodies that exist nowhere else.
Evicts least-recently-read unpinned bodies until total_bytes/0 is within
budget. Returns the number of evicted bodies.
Sweeper interval in ms (or :infinity).
Total compressed bytes in the cache.
Functions
@spec budget() :: non_neg_integer()
The configured budget in compressed bytes.
@spec delete(Ecto.UUID.t()) :: :ok
Drops the cached body of a message (e.g. after expunge).
@spec fetch(Kantoor.Mailboxes.Message.t()) :: {:ok, binary()} | {:error, :unavailable}
Read-through fetch. A miss asks Karta for the raw bytes and caches them.
Returns {:error, :unavailable} when Karta cannot deliver; never raises.
@spec get(Ecto.UUID.t()) :: {:ok, binary()} | :miss
A cache hit as {:ok, raw} (refreshing its LRU time), else :miss.
@spec put(Ecto.UUID.t(), binary(), keyword()) :: :ok | :skipped | {:error, term()}
Caches raw for message_id. Never raises: a failure (or a body that alone
exceeds the budget) just means the next read goes to Karta.
Options: pinned: true for bodies that exist nowhere else.
@spec sweep(non_neg_integer()) :: non_neg_integer()
Evicts least-recently-read unpinned bodies until total_bytes/0 is within
budget. Returns the number of evicted bodies.
@spec sweep_interval() :: pos_integer() | :infinity
Sweeper interval in ms (or :infinity).
@spec total_bytes() :: non_neg_integer()
Total compressed bytes in the cache.