Skip to content

Commit fae8cb6

Browse files
committed
update description of snapshotCache
1 parent 563f6a3 commit fae8cb6

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/OnyxSnapshotCache.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import type {UseOnyxOptions, UseOnyxResult, UseOnyxSelector} from './useOnyx';
88
*/
99
class OnyxSnapshotCache {
1010
/**
11-
* Snapshot cache for ultimate performance - separate cache per Onyx key
11+
* Snapshot cache is a two-level map. The top-level keys are Onyx keys. The top-level values maps.
12+
* The second-level keys are a custom composite string defined by this.generateCacheKey. These represent a unique useOnyx config, which is not fully represented by the Onyx key alone.
13+
* The reason we have two levels is for performance: not to make cache access faster, but to make cache invalidation faster.
14+
* We can invalidate the snapshot cache for a given Onyx key with one map.delete operation on the top-level map, rather than having to loop through a large single-level map and delete any matching keys.
1215
*/
1316
private snapshotCache: Map<OnyxKey, Map<string, UseOnyxResult<OnyxValue<OnyxKey>>>>;
1417

0 commit comments

Comments
 (0)