1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import type {CacheDispatcher} from './ReactInternalTypes';
    
  11. import type {Cache} from './ReactFiberCacheComponent';
    
  12. 
    
  13. import {enableCache} from 'shared/ReactFeatureFlags';
    
  14. import {readContext} from './ReactFiberNewContext';
    
  15. import {CacheContext} from './ReactFiberCacheComponent';
    
  16. 
    
  17. function getCacheSignal(): AbortSignal {
    
  18.   if (!enableCache) {
    
  19.     throw new Error('Not implemented.');
    
  20.   }
    
  21.   const cache: Cache = readContext(CacheContext);
    
  22.   return cache.controller.signal;
    
  23. }
    
  24. 
    
  25. function getCacheForType<T>(resourceType: () => T): T {
    
  26.   if (!enableCache) {
    
  27.     throw new Error('Not implemented.');
    
  28.   }
    
  29.   const cache: Cache = readContext(CacheContext);
    
  30.   let cacheForType: T | void = (cache.data.get(resourceType): any);
    
  31.   if (cacheForType === undefined) {
    
  32.     cacheForType = resourceType();
    
  33.     cache.data.set(resourceType, cacheForType);
    
  34.   }
    
  35.   return cacheForType;
    
  36. }
    
  37. 
    
  38. export const DefaultCacheDispatcher: CacheDispatcher = {
    
  39.   getCacheSignal,
    
  40.   getCacheForType,
    
  41. };