diff --git a/lib/OnyxCache.js b/lib/OnyxCache.js index e7f6f58fb..f68315424 100644 --- a/lib/OnyxCache.js +++ b/lib/OnyxCache.js @@ -179,16 +179,13 @@ class OnyxCache { * Remove keys that don't fall into the range of recently used keys */ removeLeastRecentlyUsedKeys() { - if (this.recentKeys.size <= this.maxRecentKeysSize) { - return; + while (this.recentKeys.size > this.maxRecentKeysSize) { + const iterator = this.recentKeys.values(); + const value = iterator.next().value; + if (value !== undefined) { + this.drop(value); + } } - - // Get the last N keys by doing a negative slice - const recentlyAccessed = [...this.recentKeys].slice(-this.maxRecentKeysSize); - const storageKeys = _.keys(this.storageMap); - const keysToRemove = _.difference(storageKeys, recentlyAccessed); - - _.each(keysToRemove, this.drop); } /**