diff --git a/lib/Onyx.js b/lib/Onyx.js index 3777fdfc..1eaf4b06 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -411,12 +411,14 @@ function cleanCache() { /* Keep any other items with active connections * Note: after `splice` the array no longer contains the `mostRecent` */ const stillConnected = recentlyAccessedKeys.filter((key) => { - const hasRemainingConnections = _.some(callbackToStateMapping, mapping => key.startsWith(mapping.key)); - if (!hasRemainingConnections) { + const shouldKeep = _.has(defaultKeyStates, key) + || _.some(callbackToStateMapping, mapping => key.startsWith(mapping.key)); + + if (!shouldKeep) { cache.drop(key); } - return hasRemainingConnections; + return shouldKeep; }); recentlyAccessedKeys = stillConnected.concat(mostRecent); @@ -616,7 +618,7 @@ function merge(key, val) { } /** - * Merge user provided default key value pairs. + * Merge stored data and user provided default key value pairs to cache * * @returns {Promise} */ @@ -643,12 +645,13 @@ function clear() { return getAllKeys() .then((keys) => { _.each(keys, (key) => { - keyChanged(key, null); - cache.set(key, null); + if (!_.has(defaultKeyStates, key)) { + keyChanged(key, null); + cache.set(key, null); + } }); }) - .then(AsyncStorage.clear) - .then(initializeWithDefaultKeyStates); + .then(AsyncStorage.clear); } /**