Skip to content

Cached flags are not persisted correctly #150

@eric-klukovich

Description

@eric-klukovich

The LaunchDarkly library caches fetched feature flags locally so they are known if the servers cannot be reached. We are encountering an issue where the cached flags are "cleared" when we load up the app offline after a Google Play store update.

We were able to track down the issue in the SDK code, and it appears that the DefaultUserManager uses a hashed value of the LDUser json string, which includes all fields. We created a LDUser using the builder code below, where the "version_code" gets updated after the release and causes the DefaultUserManager to create a new cache file instead of using the original one.

Is there a work-around where we can specify the LDUser cache name specifically, so it will not be impacted by any properties that have a dynamic value? Ideally, having the userId as the cache name would work for our use case.

val builder = LDUser.Builder(userId)
            .email(userEmailAddress)
            .firstName(userFirstName)
            .lastName(userLastName)
            .custom("company_id", companyId)
            .custom("project_id", projectId)
            .custom("version_code", appVersionCode)

We believe this method in the DefaultUserManager class is causing our issue:

public static String sharedPrefs(final LDUser user) {
     return HASHER.hash(toJson(user));
}

To reproduce

  1. Create a LDUser that a property that can change
  2. Get the current flags
  3. Change the property to another value
  4. Flags will not longer be cached

SDK version
3.1.2

Language version, developer tools
Kotlin 1.5.31

OS/platform
Android - All OS versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions