Jido.Memory.Store behaviour (Jido Memory v1.0.0)

View Source

Storage adapter behavior for memory persistence and retrieval.

jido_memory ships with ETS and Redis implementations, but callers only depend on this behavior so they can migrate to other storage backends later without API churn.

Summary

Functions

Fetches a single record and normalizes not-found semantics.

Normalizes store declarations into {module, opts} tuples.

Validates store-specific options when the store exports validate_options/1.

Types

key()

@type key() :: {namespace :: String.t(), id :: String.t()}

opts()

@type opts() :: keyword()

store()

@type store() :: module() | {module(), keyword()}

Callbacks

delete(key, opts)

@callback delete(key(), opts()) :: :ok | {:error, term()}

ensure_ready(opts)

@callback ensure_ready(opts()) :: :ok | {:error, term()}

get(key, opts)

@callback get(key(), opts()) ::
  {:ok, Jido.Memory.Record.t()} | :not_found | {:error, term()}

prune_expired(opts)

@callback prune_expired(opts()) :: {:ok, non_neg_integer()} | {:error, term()}

put(t, opts)

@callback put(Jido.Memory.Record.t(), opts()) ::
  {:ok, Jido.Memory.Record.t()} | {:error, term()}

query(t, opts)

@callback query(Jido.Memory.Query.t(), opts()) ::
  {:ok, [Jido.Memory.Record.t()]} | {:error, term()}

validate_options(opts)

(optional)
@callback validate_options(opts()) :: :ok | {:error, term()}

Functions

fetch(store_mod, key, opts)

@spec fetch(module(), key(), opts()) ::
  {:ok, Jido.Memory.Record.t()} | {:error, term()}

Fetches a single record and normalizes not-found semantics.

normalize_store(mod)

@spec normalize_store(store() | nil) ::
  {:ok, {module(), keyword()}} | {:error, term()}

Normalizes store declarations into {module, opts} tuples.

validate_options(store_mod, opts)

@spec validate_options(module(), opts()) :: :ok | {:error, term()}

Validates store-specific options when the store exports validate_options/1.