Jido.Storage.ETS (Jido v2.0.0-rc.4)

View Source

ETS-based storage adapter for agent checkpoints and thread journals.

Fast in-memory storage for development and testing. Not restart-safe - all data is lost when the BEAM stops.

Usage

defmodule MyApp.Jido do
  use Jido,
    otp_app: :my_app,
    storage: {Jido.Storage.ETS, table: :my_jido_storage}
end

Options

  • :table - Base table name (default: :jido_storage). Creates three tables:
    • {table, :checkpoints} - Agent checkpoint data (set)
    • {table, :threads} - Thread entries ordered by {thread_id, seq} (ordered_set)
    • {table, :thread_meta} - Thread metadata (set)

Concurrency

Thread operations use atomic ETS operations. The expected_rev option in append_thread/3 provides optimistic concurrency control.

Summary

Functions

Append entries to a thread.

Delete a checkpoint by key.

Delete a thread and all its entries.

Retrieve a checkpoint by key.

Load a thread by ID, reconstructing from stored entries.

Store a checkpoint, overwriting any existing value.

Types

opts()

@type opts() :: keyword()

Functions

append_thread(thread_id, entries, opts)

@spec append_thread(String.t(), [Jido.Thread.Entry.t()], opts()) ::
  {:ok, Jido.Thread.t()} | {:error, term()}

Append entries to a thread.

Options

  • :expected_rev - If provided, the append will fail with {:error, :conflict} if the current thread revision doesn't match.
  • :metadata - Thread metadata to merge (only used when creating new thread).

delete_checkpoint(key, opts)

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

Delete a checkpoint by key.

delete_thread(thread_id, opts)

@spec delete_thread(String.t(), opts()) :: :ok | {:error, term()}

Delete a thread and all its entries.

get_checkpoint(key, opts)

@spec get_checkpoint(term(), opts()) :: {:ok, term()} | :not_found | {:error, term()}

Retrieve a checkpoint by key.

Returns {:ok, data} if found, :not_found otherwise.

load_thread(thread_id, opts)

@spec load_thread(String.t(), opts()) ::
  {:ok, Jido.Thread.t()} | :not_found | {:error, term()}

Load a thread by ID, reconstructing from stored entries.

Returns {:ok, thread} if entries exist, :not_found otherwise.

put_checkpoint(key, data, opts)

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

Store a checkpoint, overwriting any existing value.