Interface PersistentDataStore


public interface PersistentDataStore
Interface for a data store that holds feature flag data and other SDK properties in a simple string format.

The SDK has a default implementation which uses the Android SharedPreferences API. A custom implementation of this interface could store data somewhere else, or use that API in a different way.

Each data item is uniquely identified by the combination of a "namespace" and a "key", and has a string value. These are defined as follows:

  • Both the namespace and the key are non-empty strings.
  • Both the namespace and the key contain only alphanumeric characters, hyphens, and underscores.
  • The value can be any non-null string, including an empty string.

The store implementation does not need to worry about adding a LaunchDarkly-specific prefix to namespaces to distinguish them from storage that is used for other purposes; the SDK will take care of that at a higher level. PersistentDataStore is just a low-level storage mechanism.

The SDK will also provide its own caching layer on top of the persistent data store; the data store implementation should not provide caching, but simply do every query or update that the SDK tells it to do.

Error handling is defined as follows: if any data store operation encounters an I/O error, or is otherwise unable to complete its task, it should throw an exception to make the SDK aware of this. The SDK will decide whether to log the exception.

Since:
4.0.0
  • Method Details

    • getValue

      String getValue(String storeNamespace, String key)
      Attempts to retrieve a string value from the store.
      Parameters:
      storeNamespace - the namespace identifier
      key - the unique key within that namespace
      Returns:
      the value, or null if not found
    • setValue

      void setValue(String storeNamespace, String key, String value)
      Attempts to update or remove a string value in the store.
      Parameters:
      storeNamespace - the namespace identifier
      key - the unique key within that namespace
      value - the new value, or null to remove the key
    • setValues

      void setValues(String storeNamespace, Map<String,String> keysAndValues)
      Attempts to update multiple values atomically.
      Parameters:
      storeNamespace - the namespace identifier
      keysAndValues - the keys and values to update
    • getKeys

      Collection<String> getKeys(String storeNamespace)
      Returns all keys that exist in the namespace.
      Parameters:
      storeNamespace - the namespace identifier
      Returns:
      the keys
    • getAllNamespaces

      Collection<String> getAllNamespaces()
      Returns all namespaces that exist in the data store.

      This may be an inefficient operation, but the SDK will not call this method on a regular basis. It is used only when migrating data from earlier SDK versions.

      Returns:
      the namespaces
    • clear

      void clear(String storeNamespace, boolean fullyDelete)
      Removes any values that currently exist in the given namespace.
      Parameters:
      storeNamespace - the namespace identifier
      fullyDelete - true to purge all data structures related to the namespace, false to simply leave it empty