Remote config
Read runtime config on the first frame from shipped defaults and an on-device cache, and fetch the project's key/value bundle to refresh it.
Remote config holds values the app reads at runtime and needs to change without a release: copy, pricing, thresholds, default selections. Config bundles hold strings, numbers, booleans and structured JSON; feature flags hold on/off gates. One bundle per project. A signed-in user's bundle has each key's segment and percentage conditions applied; before sign-in it holds each key's default value.
Two ways to read it:
config.getCached(key, default)returns a value at once, with no request, so the first screen can use it. It reads the last fetch, else the value the device cached on an earlier launch, else the defaults your app ships with (configDefaults), else the default you pass.config.fetch()requests the bundle. Its result also refreshes whatgetCachedreturns.
Quick start
Pass the values your app ships with at configure, then read config anywhere without waiting:
Startup values: defaults and the device cache
getCached answers from what the SDK holds, in this order:
- The last fetch made since launch (
config.fetch(), or the background refresh below). - The device cache: the last bundle a fetch returned, saved per project and per signed-in user, read back on the next launch.
configDefaults: the values your app ships with, passed at configure.- The default you pass to
getCached.
A JSON null counts as no value. A value of another type than the default you pass (a string where the default is a number) returns your default, so a typed read never hands back the wrong type.
Background refresh. The first getCached call for each user starts one config.fetch() in the background; its result replaces the cached values, and later reads return it. That happens once after configure, and once more after a sign-in or sign-out changes who is reading, so a signed-in user's own values arrive on their next read. Configure itself sends no request, and an app that never reads cached config makes no extra one. A failed refresh (offline) leaves the cached values in place.
Kill switch. The server leaves a config switched off with its kill switch (is_active: false) out of the bundle. The next successful fetch removes that key from the cache, so getCached falls back to configDefaults and then your default. Ship the safe value as the default for any key you may switch off.
Per project and user. Each project (each client key and environment) has its own cache; one project never reads another's. Inside it, each signed-in user has their own values, and the device keeps the five most recently used users. A signed-in user reads only their own values. Before sign-in (for example a native app at launch), and for any key a user's own values don't hold yet, the SDK reads the signed-out values: the bundle fetched without a session, which holds each key's default value and nothing targeted at a user. A response the server evaluated without a session although the app was signed in (the session had expired) is saved as signed-out values and leaves the user's own untouched.
Sign-out deletes the signed-out user's cached values; getCached then returns the signed-out values, then configDefaults, until the next fetch. A response still in flight for the signed-out session is never cached.
Where the cache lives:
| SDK | Storage |
|---|---|
| Web, React | localStorage, under the configured storage prefix (with sessionPersistence: 'memory', the page's memory) |
| React Native, Expo | AsyncStorage |
| iOS (Swift) | Application Support/<bundle id>/com.layers.amba, excluded from backups |
| Android (Kotlin) | noBackupFilesDir/com.layers.amba; pass a context to configure (without one the cache lives in memory for the process) |
| Flutter | the plugin's Application Support (iOS) or no-backup files (Android) directory |
| Unity | Application.persistentDataPath/com.layers.amba |
| Node | none (server-side; fetch per request) |
Before configure finishes
On Web and React Native, configure() is asynchronous. A getCached call that runs while it is
still loading returns the configDefaults passed to that configure() call, then your default.
Operations
fetch()
Returns a single bundle and refreshes the cache:
The response carries Cache-Control: private, max-age=300, so in a browser a repeat config.fetch() within five minutes can return the browser's cached copy.
getCached(key, default)
| SDK | Signature |
|---|---|
| Web, React Native, Expo | Amba.config.getCached<T>(key: string, defaultValue?: T): T |
| React | useConfigValue<T>(key: string, defaultValue: T): T |
| Swift | Amba.config.getCached(key: String, default: T) -> T, and getCached(key:) -> Any? |
| Kotlin | Amba.config.getCached(key, default) for String, Boolean, Int, Long, Double; getCached(key): JsonElement? |
| Dart | Amba.config.getCached<T>(String key, T defaultValue); getCached<Object?>(key, null) for the raw value |
| C# | Amba.Config.GetCached<T>(string key, T defaultValue), and GetCached(string key): JToken |
Patterns
Per-flag vs. config
Use feature flags for on/off decisions. Use config for values like copy, pricing, thresholds:
Config evaluates each key's conditions for the signed-in user (defaults before sign-in), and flags return the same project-wide set of enabled flags to every user.
Refresh
The SDK refreshes on the first cached read for each user. Call config.fetch() whenever you want current values beyond that: on app foreground, or after a known server-side update. Each successful fetch updates what getCached returns.
Reference
- Client API — config — endpoint reference.
- Remote config — kill switch and change history.
- Auth feature — prerequisite.
- Flags feature — for on/off gating.
- Per-platform quickstarts: Web, Node, iOS, Android, Flutter, Unity.