Karta.Cache (Karta v1.0.0)

An in-memory (ETS) copy of data the SMTP listeners need for every command: domains, routes, credentials, suppressions, server settings. SMTP replies must never wait on the database, so lookups read ETS in the caller's process.

Each cache is one process and one named table, filled by a Karta.Cache.Loader. It loads at start and then every reload_interval; reload/1 reloads at once (for change notifications). Until the first successful load the cache is cold and fetch/2 returns :cold; callers then answer with a temporary failure (451 4.3.2). After that a failed reload keeps the previous data (stale data beats refusing mail) and is logged.

Summary

Functions

Returns a specification to start this module under a supervisor.

Looks up key. Never calls the database or the cache process.

Reloads now. Returns :ok or the loader's error.

Options: name (also the ETS table name), loader (a module), and reload_interval in milliseconds (default 300 000).

True once the first load has succeeded.

Types

name()

@type name() :: atom()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

fetch(name, key)

@spec fetch(name(), term()) :: {:ok, term()} | :error | :cold

Looks up key. Never calls the database or the cache process.

reload(name)

@spec reload(name()) :: :ok | {:error, term()}

Reloads now. Returns :ok or the loader's error.

start_link(opts)

Options: name (also the ETS table name), loader (a module), and reload_interval in milliseconds (default 300 000).

warm?(name)

@spec warm?(name()) :: boolean()

True once the first load has succeeded.