1import pathConst from '@/constants/pathConst'; 2import {MMKV} from 'react-native-mmkv'; 3 4const _mmkvCache: Record<string, MMKV> = {}; 5 6// @ts-ignore; 7global.mmkv = _mmkvCache; 8 9// Internal Method 10const getOrCreateMMKV = (dbName: string, cachePath = false) => { 11 if (_mmkvCache[dbName]) { 12 return _mmkvCache[dbName]; 13 } 14 15 const newStore = new MMKV({ 16 id: dbName, 17 path: cachePath ? pathConst.mmkvCachePath : pathConst.mmkvPath, 18 }); 19 20 _mmkvCache[dbName] = newStore; 21 return newStore; 22}; 23 24export default getOrCreateMMKV; 25