AgentSessionManager.Adapters.InMemorySessionStore (AgentSessionManager v0.8.0)

Copy Markdown View Source

In-memory implementation of the SessionStore behaviour.

This adapter stores all session data in memory using a GenServer with ETS tables for efficient concurrent reads. It is designed primarily for testing and development environments.

Design

  • Uses ETS tables for concurrent read access
  • GenServer handles writes to ensure consistency
  • Events are stored in an append-only log with preserved order
  • All writes are idempotent (same ID updates, doesn't duplicate)
  • Thread-safe for concurrent access

Data Structures

  • Sessions: ETS table keyed by session_id
  • Runs: ETS table keyed by run_id with session_id index
  • Events: Append-only list stored in GenServer state (maintains order)
    • Also indexed in ETS by event_id for deduplication

Usage

{:ok, store} = InMemorySessionStore.start_link([])

# Use via SessionStore port
SessionStore.save_session(store, session)
{:ok, session} = SessionStore.get_session(store, session_id)

Options

  • :name - Optional name for the GenServer (default: none)

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts the in-memory session store.

Stops the session store.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the in-memory session store.

Options

  • :name - Optional name to register the GenServer

Examples

{:ok, store} = InMemorySessionStore.start_link([])
{:ok, store} = InMemorySessionStore.start_link(name: :my_store)

stop(server)

@spec stop(GenServer.server()) :: :ok

Stops the session store.