Persistent Storage
Persistent storage takes an “adapter” approach, allowing you to plug in a storage solution of your choice to store assignments, which can then be referenced later to ensure a user stays in the same bucket. You can implement an adapter that uses Local Storage, or one that uses remote storage, to enable persistence across multiple devices. The user persistent storage interface consists of just aload/loadAsync, save, delete API for read/write operations.
Persistent Storage is currently supported on:
- The modern
Javascript,React, andReact NativeSDKs, including on-device evaluation Android, on-device evaluationonlyiOS, on-device evaluationonly- See below for more information on Android and iOS Support
Persistent Storage Logic
- Providing a storage adapter on Statsig initialization will give the SDK access to read & write on your custom storage
- Providing user persisted values to
get_experimentwill inform the SDK to- save the evaluation of the current user on first evaluation
- load the previously saved evaluation of a persisted user on subsequent evaluations
- delete the previously saved evaluation of a persisted user if the experiment is no longer active
- Not providing user persisted values to
get_experimentwill delete a previously saved evaluation
Example usage
- Javascript
- React
- Android On-Device Eval
- JS On-Device Eval
- JS (legacy)
Support in iOS and Android SDKs
Android and iOS SDKs offer a simplified version of Persistent Storage calledkeepDeviceValues that relies on on-device storage. While this is less flexible its simple to leverage - with a simple boolean flag. When enabled, the SDK (under the hood in the getExperiment/getLayer call) will check for previous stored value, and use those instead, even if allocation or targeting has changed. When the experiment ends - the SDK will stop persisting values.