Raxol.Core.Config.Store (Raxol Core v2.4.0)

Copy Markdown View Source

ETS-backed configuration store for fast concurrent reads.

This module provides the runtime storage layer for configuration. It uses ETS for fast concurrent reads (no process serialization) and a minimal GenServer only for initialization and file persistence.

Design

  • ETS for all reads: No mailbox serialization, multiple readers can access concurrently
  • GenServer only for: Initialization, file I/O, auto-save timer
  • Pure functions from Raxol.Core.Config for all data transformations

Usage

# Start the store (usually in supervision tree)
{:ok, _pid} = Config.Store.start_link([])

# Read (fast ETS lookup, no process call)
width = Config.Store.get(:terminal, :width)
terminal = Config.Store.get_namespace(:terminal)

# Write (goes through GenServer for consistency)
Config.Store.put(:terminal, :width, 120)

# File operations
Config.Store.load_from_file()
Config.Store.save_to_file()

Summary

Functions

Returns a specification to start this module under a supervisor.

Gets a config value. This is a direct ETS read - no process serialization.

Gets the entire config. Direct ETS read.

Gets an entire namespace. Direct ETS read.

Loads config from file, merging with current config.

Sets a config value.

Sets an entire namespace.

Resets a namespace to default values.

Saves current config to file.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get(namespace, key, default \\ nil)

Gets a config value. This is a direct ETS read - no process serialization.

Examples

Config.Store.get(:terminal, :width)
Config.Store.get(:terminal, :missing, 0)

get_all()

@spec get_all() :: Raxol.Core.Config.t()

Gets the entire config. Direct ETS read.

get_namespace(namespace)

@spec get_namespace(Raxol.Core.Config.namespace()) :: map()

Gets an entire namespace. Direct ETS read.

Examples

Config.Store.get_namespace(:terminal)

load_from_file()

@spec load_from_file() :: :ok | {:error, any()}

Loads config from file, merging with current config.

put(namespace, key, value)

Sets a config value.

Examples

Config.Store.put(:terminal, :width, 120)

put_namespace(namespace, namespace_config)

@spec put_namespace(Raxol.Core.Config.namespace(), map()) :: :ok

Sets an entire namespace.

Examples

Config.Store.put_namespace(:terminal, %{width: 120, height: 40})

reset_namespace(namespace)

@spec reset_namespace(Raxol.Core.Config.namespace()) :: :ok

Resets a namespace to default values.

save_to_file()

@spec save_to_file() :: :ok | {:error, any()}

Saves current config to file.

start_link(opts)