Interface PersistentDataStore
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 Summary
Modifier and TypeMethodDescriptionvoid
Removes any values that currently exist in the given namespace.Returns all namespaces that exist in the data store.Returns all keys that exist in the namespace.Attempts to retrieve a string value from the store.void
Attempts to update or remove a string value in the store.void
Attempts to update multiple values atomically.
-
Method Details
-
getValue
Attempts to retrieve a string value from the store.- Parameters:
storeNamespace
- the namespace identifierkey
- the unique key within that namespace- Returns:
- the value, or null if not found
-
setValue
Attempts to update or remove a string value in the store.- Parameters:
storeNamespace
- the namespace identifierkey
- the unique key within that namespacevalue
- the new value, or null to remove the key
-
setValues
Attempts to update multiple values atomically.- Parameters:
storeNamespace
- the namespace identifierkeysAndValues
- the keys and values to update
-
getKeys
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
Removes any values that currently exist in the given namespace.- Parameters:
storeNamespace
- the namespace identifierfullyDelete
- true to purge all data structures related to the namespace, false to simply leave it empty
-