Offline Support

Koolbase caches your feature flags, remote config, and version policy locally so your app works even when there is no network connection.

In the browser

A browser has no local database for the SDK, so on the web every database read is live and every write goes straight out. Flags, config and version policy are still cached as described here.

What gets cached

On the first successful SDK init, the bootstrap snapshot is persisted to local storage using shared_preferences. This snapshot includes:

Feature flagsAll flag keys and their current evaluated values
Remote configAll config keys and values
Version policyMinimum version, update mode, message, and store URL

What is not cached

This page covers flags, config and version policy. Database reads and writes have their own offline layer — cached reads and a queue of writes that sync later — described in Database → Offline Support. The session is kept in the device's secure storage, so a signed-in person stays signed in offline.

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. Every flag check returns false and every config read returns its fallback.

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.

lib/main.dart
Dart
// Initializing is safe with no network
await Koolbase.initialize(const KoolbaseConfig(
  publicKey: 'pk_live_...',
  baseUrl: 'https://api.koolbase.com',
));
// No network and no cache: no flags, no config, no version policy

// These all return their fallbacks safely
final show = Koolbase.isEnabled('new_ui');            // false
final url  = Koolbase.configString('api_url',
  fallback: 'https://api.myapp.com');                 // the fallback
final ver  = Koolbase.checkVersion();                 // upToDate

Cache 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.

lib/main.dart
Dart
// Flutter: change how often it refreshes (optional)
await Koolbase.initialize(const KoolbaseConfig(
  publicKey: 'pk_live_...',
  baseUrl: 'https://api.koolbase.com',
  refreshInterval: Duration(seconds: 30),
));

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

A week-old cached snapshot is better than an empty state. Always prefer the cached values as the safe fallback, and let the background refresh bring them up to date when connectivity returns.

Listen for cache updates

If you want to react when new flag or config values arrive from the server, listen to the update stream:

lib/main.dart
Dart
// Listen for snapshot updates
Koolbase.onUpdate.listen((_) {
  // New flags/config loaded — refresh your UI if needed
  setState(() {});
  print('Koolbase snapshot refreshed');
});