GenServer that manages the persistent_term cache and DB writes.
Each use PhoenixFlags module starts its own Server instance,
named after the module. Reads go directly to :persistent_term (zero-cost).
Writes go through the GenServer to serialise DB updates and cache reloads.
Summary
Functions
Returns all config entries grouped by category.
Returns all audit log entries, newest first.
Returns audit log entries for a specific key, newest first.
Returns a specification to start this module under a supervisor.
Returns the config for the given instance. Used by the UI to resolve actor.
Deletes a targeting rule by id. Its conditions go with it.
Returns the cached value for a config key.
Adds a targeting rule to a flag.
Returns the targeting rules for a flag, in evaluation order.
Updates a config entry and refreshes the cache.
Returns the variant assigned to identity for a :variant flag.
Functions
Returns all config entries grouped by category.
Returns all audit log entries, newest first.
Raises PhoenixFlags.Error unless the instance is configured with audit: true.
Returns audit log entries for a specific key, newest first.
Raises PhoenixFlags.Error unless the instance is configured with audit: true.
Returns a specification to start this module under a supervisor.
See Supervisor.
Returns the config for the given instance. Used by the UI to resolve actor.
Deletes a targeting rule by id. Its conditions go with it.
Returns the cached value for a config key.
Targeting rules are consulted first: if one matches the request context, its
value wins over the stored value. See PhoenixFlags.Target.
When cache_enabled: false, checks the process dictionary first
(for test overrides), then targeting rules, then falls back to a direct DB read.
Options
:context— attributes for targeting rules, overriding the process-scopedPhoenixFlags.Context. Given neither, targeting is skipped entirely.
Raises for a :variant flag: it holds a split rather than a single value, and
returning the struct would leak it into application code. Use variant/4.
Adds a targeting rule to a flag.
attrs takes :value and :conditions, and optionally :position:
put_target(MyApp.SystemConfig, "enable_benefits",
conditions: [[attribute: :company_id, operator: :in, values: [123]]],
value: "true"
)The value must be valid for the flag's type, checked with the same rules a
dashboard save goes through. :secret flags cannot be targeted — a rule value
would sit in the targets table as plaintext, defeating the encryptor.
Returns the targeting rules for a flag, in evaluation order.
Updates a config entry and refreshes the cache.
When cache_enabled: false, runs in the caller's process for Ecto sandbox compatibility.
Accepts an optional :timeout (in milliseconds, default 5000).
Returns the variant assigned to identity for a :variant flag.
Deterministic for a given identity, split and seed — see PhoenixFlags.Variant.
Does no database or process work: the split is parsed once when the cache
loads, so this is a :persistent_term read, a hash and a short list walk.
Options
:default— returned when the flag does not exist, is not a:variantflag, the instance is not running, or the identity is unusable. Defaults tonil.:telemetry— whentrue, emits[:phoenix_flags, :variant, :assigned]with%{flag: key, identity: identity, variant: variant, instance: instance}as metadata, so exposures can be piped into your own analytics. Off by default to keep the read path free.:context— attributes for targeting rules, overriding the process-scoped context. A matching rule pins the caller to its variant, ahead of the split.:now— current time in milliseconds, for testing TTL rollover.