import { getIndexPatternKey , fetchIndexPattern } from '../../../../common/index_patterns_utils' ; import type { IndexPatternsService } from '../../../../../../data/server' ; import type { IndexPatternValue , FetchedIndexPattern } from '../../../../common/types' ; export const getCachedIndexPatternFetcher = ( indexPatternsService , globalOptions = { fetchKibanaIndexForStringIndexes : false , } ) => { const cache = new Map ( ) ; return async ( indexPatternValue , fetchKibanaIndexForStringIndexes = globalOptions . fetchKibanaIndexForStringIndexes ) : Promise < FetchedIndexPattern > => { const key = `${ getIndexPatternKey ( indexPatternValue ) }:${ fetchKibanaIndexForStringIndexes }` ; if ( cache . has ( key ) ) { return cache . get ( key ) ; } const fetchedIndex = fetchIndexPattern ( indexPatternValue , indexPatternsService , { fetchKibanaIndexForStringIndexes , } ) ; cache . set ( key , fetchedIndex ) ; return fetchedIndex ; } ; } ; export type CachedIndexPatternFetcher = ReturnType < typeof getCachedIndexPatternFetcher > ;