Jido.Storage.File
(Jido v2.0.0-rc.4)
View Source
File-based storage adapter for Jido.
Provides persistent storage for agent checkpoints and thread journals using a directory-based layout. Suitable for simple production deployments.
Usage
defmodule MyApp.Jido do
use Jido,
otp_app: :my_app,
storage: {Jido.Storage.File, path: "priv/jido/storage"}
endOptions
:path- Base directory path (required). Created if it doesn't exist.
Directory Layout
base_path/
├── checkpoints/
│ └── {key_hash}.term # Serialized checkpoint
└── threads/
└── {thread_id}/
├── meta.term # {rev, created_at, updated_at, metadata}
└── entries.log # Length-prefixed binary framesConcurrency
Uses :global.trans/3 for thread-level locking to ensure safe concurrent access.
Summary
Functions
Append entries to a thread with optimistic concurrency.
Delete a checkpoint.
Delete a thread and all its data.
Retrieve a checkpoint by key.
Load a thread from disk.
Store a checkpoint with atomic write semantics.
Types
Functions
@spec append_thread(String.t(), [Jido.Thread.Entry.t()], opts()) :: {:ok, Jido.Thread.t()} | {:error, term()}
Append entries to a thread with optimistic concurrency.
Options:
:expected_rev- Expected current revision. Fails with{:error, :conflict}if the current revision doesn't match.
Uses a global lock to ensure safe concurrent access.
Delete a checkpoint.
Returns :ok even if the file doesn't exist.
Delete a thread and all its data.
Removes the entire thread directory.
Retrieve a checkpoint by key.
Returns {:ok, data} if found, :not_found if the file doesn't exist,
or {:error, reason} on failure.
@spec load_thread(String.t(), opts()) :: {:ok, Jido.Thread.t()} | :not_found | {:error, term()}
Load a thread from disk.
Reads the meta file and entries log, reconstructing a %Jido.Thread{}.
Returns :not_found if the thread directory doesn't exist.
Store a checkpoint with atomic write semantics.
Writes to a temporary file first, then renames for atomicity.