Skip to content

Commit

Permalink
refactor: update Onyx.remove and Onyx.clear to cache a null value
Browse files Browse the repository at this point in the history
When we remove values from storage we cache that the value was removed from storage
The next time someone requests this value we can tell them right away it's null
and they don't need to wait to read this from storage
  • Loading branch information
kidroca committed Jun 9, 2021
1 parent d322991 commit b0cf26c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ function disconnect(connectionID, keyToRemoveFromEvictionBlocklist) {
* @return {Promise}
*/
function remove(key) {
// Remove from cache
cache.drop(key);
// Cache the fact that the value was removed
cache.set(key, null);

// Optimistically inform subscribers
keyChanged(key, null);
Expand Down Expand Up @@ -639,7 +639,7 @@ function clear() {
.then((keys) => {
_.each(keys, (key) => {
keyChanged(key, null);
cache.drop(key);
cache.set(key, null);
});
})
.then(AsyncStorage.clear)
Expand Down

0 comments on commit b0cf26c

Please sign in to comment.