Skip to content

Commit 9fe0cee

Browse files
Don't Clear Store on Update User Same Cache Key (#29)
1 parent bd639ee commit 9fe0cee

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

lib/src/statsig_client.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ class StatsigClient {
6565
}
6666

6767
Future updateUser(StatsigUser user) async {
68-
_store.clear();
69-
_user = user.normalize(this._options);
68+
var isSameUser = user.getCacheKey() == _user.getCacheKey();
69+
if (!isSameUser) {
70+
_store.clear();
71+
}
72+
_user = user.normalize(_options);
7073
StatsigMetadata.regenSessionID();
7174

72-
await _fetchInitialValues();
75+
await _fetchInitialValues(shouldLoadCache: !isSameUser);
7376
}
7477

7578
bool checkGate(String gateName, [bool defaultValue = false]) {
@@ -164,8 +167,10 @@ class StatsigClient {
164167
return;
165168
}
166169

167-
Future<void> _fetchInitialValues() async {
168-
await _store.load(_user);
170+
Future<void> _fetchInitialValues({bool shouldLoadCache = true}) async {
171+
if (shouldLoadCache) {
172+
await _store.load(_user);
173+
}
169174
var res = await _network.initialize(_user, _store);
170175
if (res is Map) {
171176
if (res["hashed_sdk_key_used"] != null) {

0 commit comments

Comments
 (0)