Offline Support
Koolbase caches your feature flags, remote config, and version policy locally so your app works even when there is no network connection.
What gets cached
On the first successful SDK init, the bootstrap snapshot is persisted to local storage using shared_preferences. This snapshot includes:
What is not cached
First launch with no network
On the very first launch, if there is no network connection and no cached snapshot exists, the SDK initialises with empty state. All flag checks return null (or the fallback if you use ?? false) and all config reads return their fallback values.
This means your app will work on the very first launch offline — as long as you have defined sensible fallbacks for every flag and config key.
// SDK init — safe even with no network
await Koolbase.init(apiKey: 'pk_live_...');
// If no network and no cache: flags={}, config={}, version=null
// These will all return fallbacks safely
final show = Koolbase.flags['new_ui'] ?? false; // false
final url = Koolbase.config.getString('api_url',
fallback: 'https://api.myapp.com'); // fallback
final ver = await Koolbase.version.check(); // upToDateCache refresh
The SDK refreshes the cache in the background on a polling interval (default: 60 seconds). When a fresh snapshot is fetched, the in-memory state and the local cache are both updated atomically. Flag and config reads after the refresh return the latest values.
// Customise polling interval (optional)
await Koolbase.init(
apiKey: 'pk_live_...',
pollingInterval: const Duration(seconds: 30), // poll every 30s
);
// Disable polling (manual refresh only)
await Koolbase.init(
apiKey: 'pk_live_...',
pollingInterval: Duration.zero,
);
// Manually trigger a refresh
await Koolbase.refresh();Cache TTL
The cached snapshot does not expire automatically. If the app is launched offline, the last known snapshot is used regardless of how old it is. This ensures consistent behaviour in poor network conditions — your users always see something rather than a broken state.
Stale cache is better than no cache
Listen for cache updates
If you want to react when new flag or config values arrive from the server, listen to the update stream:
// Listen for snapshot updates
Koolbase.onUpdate.listen((_) {
// New flags/config loaded — refresh your UI if needed
setState(() {});
print('Koolbase snapshot refreshed');
});