From b0cf26cb80aab05bddd5588e127647fec3e7ba7c Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Wed, 9 Jun 2021 17:54:34 +0300 Subject: [PATCH] refactor: update Onyx.remove and Onyx.clear to cache a `null` value 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 --- lib/Onyx.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index 75194dc3..576bd4cf 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -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); @@ -639,7 +639,7 @@ function clear() { .then((keys) => { _.each(keys, (key) => { keyChanged(key, null); - cache.drop(key); + cache.set(key, null); }); }) .then(AsyncStorage.clear)