Arc<Mutex<CacheState>>. The snapshot is replaced atomically on each sync. Read methods never block on the network; only the background refresh thread does.
When does the SDK hit the network
Thread-safe snapshot guarantee
The snapshot is anArc<Mutex<CacheState>> shared by all clones. The mutex is held only for the duration of the replacement write - read methods lock briefly, copy the snapshot, then release immediately.
get_all_configs() and get_all_flags() are defensive copies; mutating them has no effect on the cache.
All clones share one cache
Because all clones hold anArc to the same inner state, a sync performed by any clone - whether triggered by TTL expiry, an SSE event, or a manual sync() call - is immediately visible to all other clones.
ETag / 304
Every successful sync stores the server’sETag. The next sync sends If-None-Match: <etag>. If nothing has changed:
Background sync errors
Background syncs never return errors to the caller. If the network call fails:- The existing cache continues to be served.
- The next read after the TTL elapses retries automatically.
File-type secrets
File-type secrets are written to disk on every successful sync when their value changes:0o600.
get_secret_file_path(key) returns the current PathBuf. Use this to pass a cert or key file to rustls, openssl, or any other library that expects a file path rather than an in-memory value.
Drop and cleanup
NexusClient implements Drop. When the last clone is dropped:
- The background SSE thread (if running) is signalled and joined.
- All temp files written for file-type secrets are deleted.
$TMPDIR after the client goes out of scope.
Diagnostics
Concurrency model
- All read methods (
get_config,get_secret,get_flag, …) are safe to call from any thread concurrently. - Background sync thread - at most one at a time, scheduled on TTL expiry.
- SSE thread - at most one, started when
run_stream()is called. Arc<Mutex<CacheState>>- the mutex is never held across a network call; it is only locked to read or replace the snapshot in memory.
