Central configuration store for SuperCache.
Acts as a GenServer-backed key-value store with an optimisation for
hot-path keys: values for @fast_keys are also written to :persistent_term
so reads are allocation-free (no GenServer hop).
Fast keys
The following keys are served from :persistent_term on every read:
:key_pos— tuple index used as the ETS key:partition_pos— tuple index used to select partition:num_partition— number of ETS partitions:table_type— ETS table type (:set,:bag, etc.):table_prefix— prefix for ETS table atom names
All other keys fall back to a GenServer.call/3 with a 5-second timeout.
Example
SuperCache.Config.set_config(:my_key, "value")
SuperCache.Config.get_config(:my_key)
# => "value"
# Fast key — zero-cost read
SuperCache.Config.get_config(:num_partition)
# => 8
Summary
Functions
Returns a specification to start this module under a supervisor.
Clear all configuration values and erase all :persistent_term entries
for hot keys.
Delete a configuration value from the GenServer state and :persistent_term.
Returns true when SuperCache is running in distributed mode.
Read a configuration value.
Extract the key element from a data tuple using the configured :key_pos.
Extract the partition element from a data tuple using the configured :partition_pos.
Check whether a configuration key exists in the GenServer state.
Store a configuration value.
Starts the Config GenServer.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear_config() :: :ok
Clear all configuration values and erase all :persistent_term entries
for hot keys.
@spec delete_config(any()) :: :ok
Delete a configuration value from the GenServer state and :persistent_term.
Uses a synchronous call to ensure the deletion is complete before returning, preventing race conditions with concurrent reads.
@spec distributed?() :: boolean()
Returns true when SuperCache is running in distributed mode.
Zero-cost read from :persistent_term — no GenServer hop.
This function is inlined by the compiler and is the fastest way to
check cluster mode on the hot path (called by every API operation).
Examples
SuperCache.Config.distributed?()
# => true (when cluster: :distributed was set at startup)
Read a configuration value.
Hot keys (@fast_keys) are served from :persistent_term with no
GenServer hop. All other keys use GenServer.call/3 with a 5-second
timeout.
Examples
SuperCache.Config.get_config(:num_partition)
# => 8
SuperCache.Config.get_config(:unknown_key, :default)
# => :default
Extract the key element from a data tuple using the configured :key_pos.
Raises Config if the tuple is too small.
Examples
SuperCache.Config.set_config(:key_pos, 0)
SuperCache.Config.get_key!({:user, 1, "Alice"})
# => :user
Extract the partition element from a data tuple using the configured :partition_pos.
Raises Config if the tuple is too small.
Examples
SuperCache.Config.set_config(:partition_pos, 1)
SuperCache.Config.get_partition!({:user, 1, "Alice"})
# => 1
Check whether a configuration key exists in the GenServer state.
Note: This always hits the GenServer, even for fast keys, because
:persistent_term does not distinguish between "not set" and "set to nil".
Store a configuration value.
Hot keys are also written to :persistent_term for fast subsequent reads.
Starts the Config GenServer.
Accepts a keyword list of initial configuration values.