Skip to content

goldstei/CacheIssue

Repository files navigation

CacheIssue

Minimal repro demonstrating that the Statsig Android SDK does not serve previously-cached values during the initialization window. On a second launch, even though the SDK has values persisted to disk from the previous session's network response, reads before isInitialized() returns true still return hardcoded defaults.

Demo

Demo

The Problem

In apps with complex startup (DI, multi-module init), there is a window between app launch and Statsig.initializeAsync() completing where Statsig.isInitialized() returns false. During this window, any parameter reads return the caller's hardcoded default — not the values the SDK cached to disk from the last successful network response.

This forces app developers to build their own caching layer (e.g. SharedPreferences) to serve last-known values during the pre-init window.

Repro Steps

  1. Install and launch the app (Run #1)
  2. Wait for the "Restart app" button to activate (indicates network fetch completed and values are cached to disk)
  3. Tap "Restart app" for a cold restart
  4. Observe Run #2: pre-init reads still return defaults despite cached values on disk

Results

Run #1 — First launch (no disk cache yet)

Pre-init reads return defaults (expected — SDK hasn't been initialized). After initializeAsync, values resolve from the bundled config. The updateUser call fetches from network and caches to disk.

Run #2 — Second launch (SDK has cached values on disk)

Pre-init reads still return defaults, even though the SDK has values cached from Run #1's network fetch. Post-init reads now resolve from the disk cache (note wait_time_in_seconds = 77.0 and home_screen_title = this is the test headline — different from the bundled config's 42.0).

Expected Behavior

On Run #2, pre-init reads should serve the cached values from the previous session rather than returning defaults. The SDK has this data on disk — it should be available immediately without waiting for full initialization.

Configuration

StatsigOptions(
    api = "https://www.nytimes.com/statsig",
    eventLoggingAPI = "https://www.nytimes.com/statsig",
    enableAutoValueUpdate = true,
    autoValueUpdateIntervalMinutes = 60.0,
    onDeviceEvalAdapter = OnDeviceEvalAdapter(data = bundledConfigJson),
    initializeOffline = true,
)
  • SDK version: com.statsig:android-sdk:4.45.6
  • initializeOffline = true with OnDeviceEvalAdapter (bundled config from build time)
  • After init, Statsig.updateUser() is called (matching production behavior), which triggers a network fetch and caches the response to disk

Setup

  1. Replace sdkKey in CacheIssueApp.kt with a valid client SDK key
  2. The bundled config in res/raw/statsig_client_config_bundle.json must match the SDK key's project

Build & Run

./gradlew :app:assembleDebug
adb install app/build/outputs/apk/debug/app-debug.apk

Uninstall to reset run counter: adb uninstall com.example.cacheissue

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages