AgentForge.Store (AgentForge v0.2.2)

View Source

A simple state container implementation using GenServer. Provides basic operations for state management.

Summary

Functions

Returns a specification to start this module under a supervisor.

Deletes a value from the store.

Gets a value from the store.

Puts a value in the store.

Starts the store process with an optional name.

Updates a value in the store using a function.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

delete(store \\ __MODULE__, key)

Deletes a value from the store.

Examples

iex> {:ok, _} = AgentForge.Store.start_link(name: :test_store4)
iex> AgentForge.Store.delete(:test_store4, :counter)
:ok

get(store \\ __MODULE__, key)

Gets a value from the store.

Examples

iex> {:ok, _} = AgentForge.Store.start_link(name: :test_store)
iex> AgentForge.Store.put(:test_store, :counter, 42)
iex> AgentForge.Store.get(:test_store, :counter)
{:ok, 42}
iex> AgentForge.Store.get(:test_store, :nonexistent)
{:error, :not_found}

put(store \\ __MODULE__, key, value)

Puts a value in the store.

Examples

iex> {:ok, _} = AgentForge.Store.start_link(name: :test_store2)
iex> AgentForge.Store.put(:test_store2, :counter, 42)
:ok

start_link(opts \\ [])

Starts the store process with an optional name.

update(store \\ __MODULE__, key, default, fun)

Updates a value in the store using a function.

Examples

iex> {:ok, _} = AgentForge.Store.start_link(name: :test_store3)
iex> AgentForge.Store.update(:test_store3, :counter, 0, &(&1 + 1))
:ok