Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,7 @@ class DevCycleClient private constructor(
private val variableInstanceMap: MutableMap<String, MutableMap<Any, WeakReference<Variable<*>>>> = mutableMapOf()

init {
val cachedConfig = if (disableConfigCache) null else dvcSharedPrefs.getConfig(user)
if (cachedConfig != null) {
config = cachedConfig
isConfigCached.set(true)
DevCycleLogger.d("Loaded config from cache")
observable.configUpdated(config)
}
useCachedConfigForUser(user)

initializeJob = coroutineScope.async(coroutineContext) {
isExecuting.set(true)
Expand Down Expand Up @@ -232,6 +226,10 @@ class DevCycleClient private constructor(
fetchConfig(updatedUser)
config?.variables?.let { callback?.onSuccess(it) }
} catch (t: Throwable) {
DevCycleLogger.d("Error fetching config for user_id %s", updatedUser.userId)
// In the event that the config request fails (i.e. the device is offline)
// Fallback to using a Cached Configuration for the User if available
useCachedConfigForUser(updatedUser)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a debug log above it too, makes it clearer that it's using the cached config because of the config failing

callback?.onError(t)
} finally {
handleQueuedConfigRequests()
Expand Down Expand Up @@ -555,6 +553,16 @@ class DevCycleClient private constructor(
}
}

private fun useCachedConfigForUser(user: PopulatedUser) {
val cachedConfig = if (disableConfigCache) null else dvcSharedPrefs.getConfig(user)
if (cachedConfig != null) {
config = cachedConfig
isConfigCached.set(true)
DevCycleLogger.d("Loaded config from cache for user_id %s", user.userId)
observable.configUpdated(config)
}
}

class DevCycleClientBuilder {
private var context: Context? = null
private var customLifecycleHandler: Handler? = null
Expand Down