NexusClient. All read methods are non-blocking - they hit the in-memory cache. Only CreateAsync() and SyncAsync() make network calls.
Construction
NexusClient.CreateAsync(NexusConfig, CancellationToken = default)
Creates a client and runs a blocking initial sync. The returned Task<NexusClient> resolves only after the first sync completes.
Configs
(JsonElement? value, bool found) GetConfig(string key)
Returns the resolved config value as a JsonElement (the wire-level JSON node), and a found boolean.
IReadOnlyDictionary<string, JsonElement> GetAllConfigs()
Snapshot copy of every config key-value pair currently in the cache.
public-key clients receive every config and flag the service exposes - visibility is decided server-side, with no per-entry field for a client to reason about.
Feature flags
bool GetFlag(string key, bool defaultValue = false)
Returns the is_active state of a flag, or defaultValue when the key is absent.
IReadOnlyDictionary<string, bool> GetAllFlags()
Snapshot copy of every flag key-is_active pair in the cache.
AB Testing
Task<IReadOnlyDictionary<string, bool>> EvaluateABAsync(IEnumerable<string> keys, string userId, IDictionary<string, object>? attributes, CancellationToken = default)
Evaluates one or more feature flags against the AB Testing add-on. Unlike GetFlag, this method always makes a network call.
attributes may be null - it is serialised as an empty object.
Secrets (secret key only)
string GetSecret(string key)
Returns the plaintext value of a secret. It reads the in-memory cache and makes no network call, which is why it returns a string rather than a Task<string>; it pairs with GetSecretFilePath, which is synchronous for the same reason.
string? GetSecretFilePath(string key)
Returns the absolute filesystem path of a materialised file-type secret, or null when the key is unknown or refers to a text-type secret. Always non-blocking.
File-type secrets
file-type secrets are materialised during every sync into a directory the client owns:
0700 with an unguessable name, and each file inside it is created
exclusively at 0600 with the mode applied by the creating call rather than by a chmod afterwards.
Both filename components are the first 16 hex characters of a SHA-256 digest, so neither the key name
nor the value appears in the path.
Because the value hash is part of the name, the path changes whenever the value changes - a
consumer can detect a rotation by polling GetSecretFilePath. The directory component is per client
instance, so two clients holding the same secret get separate files and one client’s disposal cannot
remove the other’s; do not persist the path beyond the client’s lifetime.
Files for secrets that disappear from a sync, or switch back to text, are deleted. The directory and
everything in it are removed by Dispose() / DisposeAsync(), and a process-exit hook removes them
if the process ends without disposing. On Windows there is no 0600 equivalent: the directory and its
files inherit the user-scoped temp ACL.
Secrets - Write API (v0.5.0) (secret key only)
Task SetSecretAsync(string key, string value, CancellationToken = default)
Creates or updates a secret with the given key and value.
Task DeleteSecretAsync(string key, CancellationToken = default)
Deletes a secret by key.
Task DeleteSecretVersionAsync(string key, int version, CancellationToken = default) (v0.5.0)
Deletes a specific version of a secret.
Disposing the client
Always dispose the client viaDispose() / DisposeAsync() (or await using) on shutdown. Disposal:
- Cancels the SSE background task (if
ConnectStream()was ever called). - Deletes every temp file written for
file-type secrets. - Releases the internally-managed
HttpClientinstances.
Metadata
Sync / lifecycle
Task SyncAsync(CancellationToken = default)
Forces a sync now, bypassing the TTL. Atomically replaces the cache. ETag / If-None-Match is used automatically; a 304 resets the TTL without downloading data. Rarely needed.
void ConnectStream()
Starts the SSE live-update background task. Idempotent - calling more than once is a no-op. See SSE live updates.
void DisconnectStream()
Stops the SSE task. Safe to call multiple times.
Dispose() / DisposeAsync()
Stops the SSE background task, deletes any file-type secret temp files, and releases the internally-managed HttpClient. Always call (or use await using) before the application exits.