diff --git a/API-INTERNAL.md b/API-INTERNAL.md
index 34ec4bf37..5c7fe9251 100644
--- a/API-INTERNAL.md
+++ b/API-INTERNAL.md
@@ -17,6 +17,11 @@
getDeferredInitTask()
Getter - returns the deffered init task.
+afterInit(action) ⇒
+Executes an action after Onyx has been initialized.
+If Onyx is already initialized, the action is executed immediately.
+Otherwise, it waits for initialization to complete before executing.
+
getSkippableCollectionMemberIDs()
Getter - returns the skippable collection member IDs.
@@ -29,7 +34,7 @@
setSnapshotMergeKeys()
Setter - sets the snapshot merge keys allowlist.
-initStoreValues(keys, initialKeyStates, evictableKeys)
+initStoreValues(keys, initialKeyStates)
Sets the initial values for the Onyx store
reduceCollectionWithSelector()
@@ -106,33 +111,17 @@ If the requested key is a collection, it will return an object with all the coll
sendDataToConnection()
Sends the data obtained from the keys to the connection.
-addKeyToRecentlyAccessedIfNeeded()
-We check to see if this key is flagged as safe for eviction and add it to the recentlyAccessedKeys list so that when we
-run out of storage the least recently accessed key can be removed.
-
getCollectionDataAndSendAsObject()
Gets the data for a given an array of matching keys, combines them into an object, and sends the result back to the subscriber.
-prepareSubscriberUpdate(callback)
-Delays promise resolution until the next macrotask to prevent race condition if the key subscription is in progress.
-
-scheduleSubscriberUpdate()
-Schedules an update that will be appended to the macro task queue (so it doesn't update the subscribers immediately).
-
-scheduleNotifyCollectionSubscribers()
-This method is similar to scheduleSubscriberUpdate but it is built for working specifically with collections
-so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
-subscriber callbacks receive the data in a different format than they normally expect and it breaks code.
-
remove()
Remove a key from Onyx and update the subscribers
retryOperation()
-Handles storage operation failures based on the error type:
+Handles storage operation failures by retrying the operation.
-- Storage capacity errors: evicts data and retries the operation
- Invalid data errors: logs an alert and throws an error
-- Other errors: retries the operation
+- Other errors: retries the operation up to MAX_STORAGE_OPERATION_RETRY_ATTEMPTS times
broadcastUpdate()
@@ -223,6 +212,20 @@ Getter - returns the default key states.
Getter - returns the deffered init task.
**Kind**: global function
+
+
+## afterInit(action) ⇒
+Executes an action after Onyx has been initialized.
+If Onyx is already initialized, the action is executed immediately.
+Otherwise, it waits for initialization to complete before executing.
+
+**Kind**: global function
+**Returns**: The result of the action
+
+| Param | Description |
+| --- | --- |
+| action | The action to execute after initialization |
+
## getSkippableCollectionMemberIDs()
@@ -249,7 +252,7 @@ Setter - sets the snapshot merge keys allowlist.
**Kind**: global function
-## initStoreValues(keys, initialKeyStates, evictableKeys)
+## initStoreValues(keys, initialKeyStates)
Sets the initial values for the Onyx store
**Kind**: global function
@@ -258,7 +261,6 @@ Sets the initial values for the Onyx store
| --- | --- |
| keys | `ONYXKEYS` constants object from Onyx.init() |
| initialKeyStates | initial data to set when `init()` and `clear()` are called |
-| evictableKeys | This is an array of keys (individual or collection patterns) that when provided to Onyx are flagged as "safe" for removal. |
@@ -393,7 +395,7 @@ For example:
- `getCollectionKey("sharedNVP_user_-1_something")` would return "sharedNVP_user_"
**Kind**: global function
-**Returns**: The plain collection key or throws an Error if the key is not a collection one.
+**Returns**: The plain collection key or undefined if the key is not a collection one.
| Param | Description |
| --- | --- |
@@ -444,48 +446,12 @@ keyChanged(key, value, subscriber => subscriber.initWithStoredValues === false)
## sendDataToConnection()
Sends the data obtained from the keys to the connection.
-**Kind**: global function
-
-
-## addKeyToRecentlyAccessedIfNeeded()
-We check to see if this key is flagged as safe for eviction and add it to the recentlyAccessedKeys list so that when we
-run out of storage the least recently accessed key can be removed.
-
**Kind**: global function
## getCollectionDataAndSendAsObject()
Gets the data for a given an array of matching keys, combines them into an object, and sends the result back to the subscriber.
-**Kind**: global function
-
-
-## prepareSubscriberUpdate(callback)
-Delays promise resolution until the next macrotask to prevent race condition if the key subscription is in progress.
-
-**Kind**: global function
-
-| Param | Description |
-| --- | --- |
-| callback | The keyChanged/keysChanged callback |
-
-
-
-## scheduleSubscriberUpdate()
-Schedules an update that will be appended to the macro task queue (so it doesn't update the subscribers immediately).
-
-**Kind**: global function
-**Example**
-```js
-scheduleSubscriberUpdate(key, value, subscriber => subscriber.initWithStoredValues === false)
-```
-
-
-## scheduleNotifyCollectionSubscribers()
-This method is similar to scheduleSubscriberUpdate but it is built for working specifically with collections
-so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
-subscriber callbacks receive the data in a different format than they normally expect and it breaks code.
-
**Kind**: global function
@@ -496,10 +462,9 @@ Remove a key from Onyx and update the subscribers
## retryOperation()
-Handles storage operation failures based on the error type:
-- Storage capacity errors: evicts data and retries the operation
+Handles storage operation failures by retrying the operation.
- Invalid data errors: logs an alert and throws an error
-- Other errors: retries the operation
+- Other errors: retries the operation up to MAX_STORAGE_OPERATION_RETRY_ATTEMPTS times
**Kind**: global function
diff --git a/README.md b/README.md
index dd32a0e66..5473dbb6a 100644
--- a/README.md
+++ b/README.md
@@ -314,43 +314,6 @@ If a platform needs to use a separate library (like using MMVK for react-native)
[Docs](./API.md)
-# Cache Eviction
-
-Different platforms come with varying storage capacities and Onyx has a way to gracefully fail when those storage limits are encountered. When Onyx fails to set or modify a key the following steps are taken:
-1. Onyx looks at a list of recently accessed keys (access is defined as subscribed to or modified) and locates the key that was least recently accessed
-2. It then deletes this key and retries the original operation
-
-By default, Onyx will not evict anything from storage and will presume all keys are "unsafe" to remove unless explicitly told otherwise.
-
-**To flag a key as safe for removal:**
-- Add the key to the `evictableKeys` option in `Onyx.init(options)`
-- Implement `canEvict` in the Onyx config for each component subscribing to a key
-- The key will only be deleted when all subscribers return `true` for `canEvict`
-
-e.g.
-```js
-Onyx.init({
- evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
-});
-```
-
-```js
-const ReportActionsView = ({reportID, isActiveReport}) => {
- const [reportActions] = useOnyx(
- `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}_`,
- {canEvict: () => !isActiveReport}
- );
-
- return (
-
- {/* Render with reportActions data */}
-
- );
-};
-
-export default ReportActionsView;
-```
-
# Benchmarks
Provide the `captureMetrics` boolean flag to `Onyx.init` to capture call statistics
@@ -358,7 +321,6 @@ Provide the `captureMetrics` boolean flag to `Onyx.init` to capture call statist
```js
Onyx.init({
keys: ONYXKEYS,
- evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
captureMetrics: Config.BENCHMARK_ONYX,
});
```
diff --git a/lib/Onyx.ts b/lib/Onyx.ts
index 2b836bb19..67e276a3f 100644
--- a/lib/Onyx.ts
+++ b/lib/Onyx.ts
@@ -34,8 +34,6 @@ import OnyxMerge from './OnyxMerge';
function init({
keys = {},
initialKeyStates = {},
- evictableKeys = [],
- maxCachedKeysCount = 1000,
shouldSyncMultipleInstances = !!global.localStorage,
enablePerformanceMetrics = false,
enableDevTools = true,
@@ -76,16 +74,10 @@ function init({
});
}
- if (maxCachedKeysCount > 0) {
- cache.setRecentKeysLimit(maxCachedKeysCount);
- }
-
- OnyxUtils.initStoreValues(keys, initialKeyStates, evictableKeys);
+ OnyxUtils.initStoreValues(keys, initialKeyStates);
// Initialize all of our keys with data provided then give green light to any pending connections
- Promise.all([cache.addEvictableKeysToRecentlyAccessedList(OnyxUtils.isCollectionKey, OnyxUtils.getAllKeys), OnyxUtils.initializeWithDefaultKeyStates()]).then(
- OnyxUtils.getDeferredInitTask().resolve,
- );
+ OnyxUtils.initializeWithDefaultKeyStates().then(OnyxUtils.getDeferredInitTask().resolve);
}
/**
diff --git a/lib/OnyxCache.ts b/lib/OnyxCache.ts
index fb6d4f795..1e053948d 100644
--- a/lib/OnyxCache.ts
+++ b/lib/OnyxCache.ts
@@ -3,7 +3,6 @@ import bindAll from 'lodash/bindAll';
import type {ValueOf} from 'type-fest';
import utils from './utils';
import type {OnyxKey, OnyxValue} from './types';
-import * as Str from './Str';
// Task constants
const TASK = {
@@ -25,9 +24,6 @@ class OnyxCache {
/** A list of keys where a nullish value has been fetched from storage before, but the key still exists in cache */
private nullishStorageKeys: Set;
- /** Unique list of keys maintained in access order (most recent at the end) */
- private recentKeys: Set;
-
/** A map of cached values */
private storageMap: Record>;
@@ -40,18 +36,6 @@ class OnyxCache {
*/
private pendingPromises: Map | OnyxKey[]>>;
- /** Maximum size of the keys store din cache */
- private maxRecentKeysSize = 0;
-
- /** List of keys that are safe to remove when we reach max storage */
- private evictionAllowList: OnyxKey[] = [];
-
- /** Map of keys and connection arrays whose keys will never be automatically evicted */
- private evictionBlocklist: Record = {};
-
- /** List of keys that have been directly subscribed to or recently modified from least to most recent */
- private recentlyAccessedKeys = new Set();
-
/** Set of collection keys for fast lookup */
private collectionKeys = new Set();
@@ -61,7 +45,6 @@ class OnyxCache {
constructor() {
this.storageKeys = new Set();
this.nullishStorageKeys = new Set();
- this.recentKeys = new Set();
this.storageMap = {};
this.collectionData = {};
this.pendingPromises = new Map();
@@ -82,17 +65,7 @@ class OnyxCache {
'hasPendingTask',
'getTaskPromise',
'captureTask',
- 'addToAccessedKeys',
- 'removeLeastRecentlyUsedKeys',
- 'setRecentKeysLimit',
'setAllKeys',
- 'setEvictionAllowList',
- 'getEvictionBlocklist',
- 'isEvictableKey',
- 'removeLastAccessedKey',
- 'addLastAccessedKey',
- 'addEvictableKeysToRecentlyAccessedList',
- 'getKeyForEviction',
'setCollectionKeys',
'isCollectionKey',
'getCollectionKey',
@@ -151,12 +124,8 @@ class OnyxCache {
/**
* Get a cached value from storage
- * @param [shouldReindexCache] – This is an LRU cache, and by default accessing a value will make it become last in line to be evicted. This flag can be used to skip that and just access the value directly without side-effects.
*/
- get(key: OnyxKey, shouldReindexCache = true): OnyxValue {
- if (shouldReindexCache) {
- this.addToAccessedKeys(key);
- }
+ get(key: OnyxKey): OnyxValue {
return this.storageMap[key];
}
@@ -166,7 +135,6 @@ class OnyxCache {
*/
set(key: OnyxKey, value: OnyxValue): OnyxValue {
this.addKey(key);
- this.addToAccessedKeys(key);
// When a key is explicitly set in cache, we can remove it from the list of nullish keys,
// since it will either be set to a non nullish value or removed from the cache completely.
@@ -212,7 +180,6 @@ class OnyxCache {
}
this.storageKeys.delete(key);
- this.recentKeys.delete(key);
}
/**
@@ -233,7 +200,6 @@ class OnyxCache {
for (const [key, value] of Object.entries(data)) {
this.addKey(key);
- this.addToAccessedKeys(key);
const collectionKey = this.getCollectionKey(key);
@@ -291,148 +257,12 @@ class OnyxCache {
return returnPromise;
}
- /** Adds a key to the top of the recently accessed keys */
- addToAccessedKeys(key: OnyxKey): void {
- this.recentKeys.delete(key);
- this.recentKeys.add(key);
- }
-
- /** Remove keys that don't fall into the range of recently used keys */
- removeLeastRecentlyUsedKeys(): void {
- const numKeysToRemove = this.recentKeys.size - this.maxRecentKeysSize;
- if (numKeysToRemove <= 0) {
- return;
- }
-
- const iterator = this.recentKeys.values();
- const keysToRemove: OnyxKey[] = [];
-
- const recentKeysArray = Array.from(this.recentKeys);
- const mostRecentKey = recentKeysArray[recentKeysArray.length - 1];
-
- let iterResult = iterator.next();
- while (!iterResult.done) {
- const key = iterResult.value;
- // Don't consider the most recently accessed key for eviction
- // This ensures we don't immediately evict a key we just added
- if (key !== undefined && key !== mostRecentKey && this.isEvictableKey(key)) {
- keysToRemove.push(key);
- }
- iterResult = iterator.next();
- }
-
- for (const key of keysToRemove) {
- delete this.storageMap[key];
-
- // Remove from collection data cache if this is a collection member
- const collectionKey = this.getCollectionKey(key);
- if (collectionKey && this.collectionData[collectionKey]) {
- delete this.collectionData[collectionKey][key];
- }
- this.recentKeys.delete(key);
- }
- }
-
- /** Set the recent keys list size */
- setRecentKeysLimit(limit: number): void {
- this.maxRecentKeysSize = limit;
- }
-
/** Check if the value has changed */
hasValueChanged(key: OnyxKey, value: OnyxValue): boolean {
- const currentValue = this.get(key, false);
+ const currentValue = this.get(key);
return !deepEqual(currentValue, value);
}
- /**
- * Sets the list of keys that are considered safe for eviction
- * @param keys - Array of OnyxKeys that are safe to evict
- */
- setEvictionAllowList(keys: OnyxKey[]): void {
- this.evictionAllowList = keys;
- }
-
- /**
- * Get the eviction block list that prevents keys from being evicted
- */
- getEvictionBlocklist(): Record {
- return this.evictionBlocklist;
- }
-
- /**
- * Checks to see if this key has been flagged as safe for removal.
- * @param testKey - Key to check
- */
- isEvictableKey(testKey: OnyxKey): boolean {
- return this.evictionAllowList.some((key) => this.isKeyMatch(key, testKey));
- }
-
- /**
- * Check if a given key matches a pattern key
- * @param configKey - Pattern that may contain a wildcard
- * @param key - Key to test against the pattern
- */
- private isKeyMatch(configKey: OnyxKey, key: OnyxKey): boolean {
- const isCollectionKey = configKey.endsWith('_');
- return isCollectionKey ? Str.startsWith(key, configKey) : configKey === key;
- }
-
- /**
- * Remove a key from the recently accessed key list.
- */
- removeLastAccessedKey(key: OnyxKey): void {
- this.recentlyAccessedKeys.delete(key);
- }
-
- /**
- * Add a key to the list of recently accessed keys. The least
- * recently accessed key should be at the head and the most
- * recently accessed key at the tail.
- */
- addLastAccessedKey(key: OnyxKey, isCollectionKey: boolean): void {
- // Only specific keys belong in this list since we cannot remove an entire collection.
- if (isCollectionKey || !this.isEvictableKey(key)) {
- return;
- }
-
- this.removeLastAccessedKey(key);
- this.recentlyAccessedKeys.add(key);
- }
-
- /**
- * Take all the keys that are safe to evict and add them to
- * the recently accessed list when initializing the app. This
- * enables keys that have not recently been accessed to be
- * removed.
- * @param isCollectionKeyFn - Function to determine if a key is a collection key
- * @param getAllKeysFn - Function to get all keys, defaults to Storage.getAllKeys
- */
- addEvictableKeysToRecentlyAccessedList(isCollectionKeyFn: (key: OnyxKey) => boolean, getAllKeysFn: () => Promise>): Promise {
- return getAllKeysFn().then((keys: Set) => {
- for (const evictableKey of this.evictionAllowList) {
- for (const key of keys) {
- if (!this.isKeyMatch(evictableKey, key)) {
- continue;
- }
-
- this.addLastAccessedKey(key, isCollectionKeyFn(key));
- }
- }
- });
- }
-
- /**
- * Finds a key that can be safely evicted
- */
- getKeyForEviction(): OnyxKey | undefined {
- for (const key of this.recentlyAccessedKeys) {
- if (!this.evictionBlocklist[key]) {
- return key;
- }
- }
- return undefined;
- }
-
/**
* Set the collection keys for optimized storage
*/
diff --git a/lib/OnyxConnectionManager.ts b/lib/OnyxConnectionManager.ts
index b9d8d56cd..ff9436c80 100644
--- a/lib/OnyxConnectionManager.ts
+++ b/lib/OnyxConnectionManager.ts
@@ -4,7 +4,6 @@ import type {ConnectOptions} from './Onyx';
import OnyxUtils from './OnyxUtils';
import * as Str from './Str';
import type {CollectionConnectCallback, DefaultConnectCallback, DefaultConnectOptions, OnyxKey, OnyxValue} from './types';
-import cache from './OnyxCache';
import onyxSnapshotCache from './OnyxSnapshotCache';
type ConnectCallback = DefaultConnectCallback | CollectionConnectCallback;
@@ -105,7 +104,7 @@ class OnyxConnectionManager {
this.sessionID = Str.guid();
// Binds all public methods to prevent problems with `this`.
- bindAll(this, 'generateConnectionID', 'fireCallbacks', 'connect', 'disconnect', 'disconnectAll', 'refreshSessionID', 'addToEvictionBlockList', 'removeFromEvictionBlockList');
+ bindAll(this, 'generateConnectionID', 'fireCallbacks', 'connect', 'disconnect', 'disconnectAll', 'refreshSessionID');
}
/**
@@ -239,7 +238,6 @@ class OnyxConnectionManager {
// If the connection's callbacks map is empty we can safely unsubscribe from the Onyx key.
if (connectionMetadata.callbacks.size === 0) {
OnyxUtils.unsubscribeFromKey(connectionMetadata.subscriptionID);
- this.removeFromEvictionBlockList(connection);
this.connectionsMap.delete(connection.id);
}
@@ -249,11 +247,8 @@ class OnyxConnectionManager {
* Disconnect all subscribers from Onyx.
*/
disconnectAll(): void {
- for (const [connectionID, connectionMetadata] of this.connectionsMap.entries()) {
+ for (const connectionMetadata of this.connectionsMap.values()) {
OnyxUtils.unsubscribeFromKey(connectionMetadata.subscriptionID);
- for (const callbackID of connectionMetadata.callbacks.keys()) {
- this.removeFromEvictionBlockList({id: connectionID, callbackID});
- }
}
this.connectionsMap.clear();
@@ -271,55 +266,6 @@ class OnyxConnectionManager {
// Clear snapshot cache when session refreshes to avoid stale cache issues
onyxSnapshotCache.clear();
}
-
- /**
- * Adds the connection to the eviction block list. Connections added to this list can never be evicted.
- * */
- addToEvictionBlockList(connection: Connection): void {
- if (!connection) {
- Logger.logInfo(`[ConnectionManager] Attempted to add connection to eviction block list passing an undefined connection object.`);
- return;
- }
-
- const connectionMetadata = this.connectionsMap.get(connection.id);
- if (!connectionMetadata) {
- Logger.logInfo(`[ConnectionManager] Attempted to add connection to eviction block list but no connection was found.`);
- return;
- }
-
- const evictionBlocklist = cache.getEvictionBlocklist();
- if (!evictionBlocklist[connectionMetadata.onyxKey]) {
- evictionBlocklist[connectionMetadata.onyxKey] = [];
- }
-
- evictionBlocklist[connectionMetadata.onyxKey]?.push(`${connection.id}_${connection.callbackID}`);
- }
-
- /**
- * Removes a connection previously added to this list
- * which will enable it to be evicted again.
- */
- removeFromEvictionBlockList(connection: Connection): void {
- if (!connection) {
- Logger.logInfo(`[ConnectionManager] Attempted to remove connection from eviction block list passing an undefined connection object.`);
- return;
- }
-
- const connectionMetadata = this.connectionsMap.get(connection.id);
- if (!connectionMetadata) {
- Logger.logInfo(`[ConnectionManager] Attempted to remove connection from eviction block list but no connection was found.`);
- return;
- }
-
- const evictionBlocklist = cache.getEvictionBlocklist();
- evictionBlocklist[connectionMetadata.onyxKey] =
- evictionBlocklist[connectionMetadata.onyxKey]?.filter((evictionKey) => evictionKey !== `${connection.id}_${connection.callbackID}`) ?? [];
-
- // Remove the key if there are no more subscribers.
- if (evictionBlocklist[connectionMetadata.onyxKey]?.length === 0) {
- delete evictionBlocklist[connectionMetadata.onyxKey];
- }
- }
}
const connectionManager = new OnyxConnectionManager();
diff --git a/lib/OnyxSnapshotCache.ts b/lib/OnyxSnapshotCache.ts
index 891a42460..09129c328 100644
--- a/lib/OnyxSnapshotCache.ts
+++ b/lib/OnyxSnapshotCache.ts
@@ -60,7 +60,7 @@ class OnyxSnapshotCache {
* - `selector`: Different selectors produce different results, so each selector needs its own cache entry
* - `initWithStoredValues`: This flag changes the initial loading behavior and affects the returned fetch status
*
- * Other options like `canEvict` and `reuseConnection` don't affect the data transformation
+ * Other options like `reuseConnection` don't affect the data transformation
* or timing behavior of getSnapshot, so they're excluded from the cache key for better cache hit rates.
*/
registerConsumer(options: Pick, 'selector' | 'initWithStoredValues'>): string {
diff --git a/lib/OnyxUtils.ts b/lib/OnyxUtils.ts
index 3e884e2b3..9d590aad6 100644
--- a/lib/OnyxUtils.ts
+++ b/lib/OnyxUtils.ts
@@ -4,7 +4,7 @@ import _ from 'underscore';
import DevTools from './DevTools';
import * as Logger from './Logger';
import type Onyx from './Onyx';
-import cache, {TASK} from './OnyxCache';
+import cache from './OnyxCache';
import * as Str from './Str';
import Storage from './storage';
import type {
@@ -51,20 +51,6 @@ const METHOD = {
CLEAR: 'clear',
} as const;
-// IndexedDB errors that indicate storage capacity issues where eviction can help
-const IDB_STORAGE_ERRORS = [
- 'quotaexceedederror', // Browser storage quota exceeded
-] as const;
-
-// SQLite errors that indicate storage capacity issues where eviction can help
-const SQLITE_STORAGE_ERRORS = [
- 'database or disk is full', // Device storage is full
- 'disk I/O error', // File system I/O failure, often due to insufficient space or corrupted storage
- 'out of memory', // Insufficient RAM or storage space to complete the operation
-] as const;
-
-const STORAGE_ERRORS = [...IDB_STORAGE_ERRORS, ...SQLITE_STORAGE_ERRORS];
-
// Max number of retries for failed storage operations
const MAX_STORAGE_OPERATION_RETRY_ATTEMPTS = 5;
@@ -182,9 +168,8 @@ function setSnapshotMergeKeys(keys: Set): void {
*
* @param keys - `ONYXKEYS` constants object from Onyx.init()
* @param initialKeyStates - initial data to set when `init()` and `clear()` are called
- * @param evictableKeys - This is an array of keys (individual or collection patterns) that when provided to Onyx are flagged as "safe" for removal.
*/
-function initStoreValues(keys: DeepRecord, initialKeyStates: Partial, evictableKeys: OnyxKey[]): void {
+function initStoreValues(keys: DeepRecord, initialKeyStates: Partial): void {
// We need the value of the collection keys later for checking if a
// key is a collection. We store it in a map for faster lookup.
const collectionValues = Object.values(keys.COLLECTION ?? {}) as string[];
@@ -198,9 +183,6 @@ function initStoreValues(keys: DeepRecord, initialKeyStates: Pa
DevTools.initState(initialKeyStates);
- // Let Onyx know about which keys are safe to evict
- cache.setEvictionAllowList(evictableKeys);
-
// Set collection keys in cache for optimized storage
cache.setCollectionKeys(onyxCollectionKeySet);
@@ -262,143 +244,22 @@ function get>(key: TKey): P
return Promise.resolve(cache.get(key) as TValue);
}
- // RAM-only keys should never read from storage (they may have stale persisted data
- // from before the key was migrated to RAM-only). Mark as nullish so future get() calls
- // short-circuit via hasCacheForKey and avoid re-running this branch.
- if (isRamOnlyKey(key)) {
- cache.addNullishStorageKey(key);
- return Promise.resolve(undefined as TValue);
- }
-
- const taskName = `${TASK.GET}:${key}` as const;
-
- // When a value retrieving task for this key is still running hook to it
- if (cache.hasPendingTask(taskName)) {
- return cache.getTaskPromise(taskName) as Promise;
- }
-
- // Otherwise retrieve the value from storage and capture a promise to aid concurrent usages
- const promise = Storage.getItem(key)
- .then((val) => {
- if (skippableCollectionMemberIDs.size) {
- try {
- const [, collectionMemberID] = splitCollectionMemberKey(key);
- if (skippableCollectionMemberIDs.has(collectionMemberID)) {
- // The key is a skippable one, so we set the value to undefined.
- // eslint-disable-next-line no-param-reassign
- val = undefined as OnyxValue;
- }
- } catch (e) {
- // The key is not a collection one or something went wrong during split, so we proceed with the function's logic.
- }
- }
-
- if (val === undefined) {
- cache.addNullishStorageKey(key);
- return undefined;
- }
-
- cache.set(key, val);
- return val;
- })
- .catch((err) => Logger.logInfo(`Unable to get item from persistent storage. Key: ${key} Error: ${err}`));
-
- return cache.captureTask(taskName, promise) as Promise;
+ return Promise.resolve(undefined as TValue);
}
// multiGet the data first from the cache and then from the storage for the missing keys.
function multiGet(keys: CollectionKeyBase[]): Promise