storage.ts 828 B

1234567891011121314151617181920212223242526272829303132333435
  1. // import RNDeviceInfo from 'react-native-device-info';
  2. import RNFS from 'react-native-fs-turbo';
  3. import { createMMKV, MMKV } from 'react-native-mmkv';
  4. let globalStorage: MMKV | null = null;
  5. export function getGlobalStorage() {
  6. if (!globalStorage) {
  7. globalStorage = createMMKV({
  8. id: `global`,
  9. });
  10. }
  11. return globalStorage;
  12. }
  13. let caches: MMKV | null = null;
  14. export function getCaches() {
  15. if (!caches) {
  16. caches = createMMKV({
  17. id: `caches`,
  18. path: `${RNFS.CachesDirectoryPath}`,
  19. });
  20. }
  21. return caches;
  22. }
  23. let apiCache: MMKV | null = null;
  24. export function getApiCache() {
  25. if (!apiCache) {
  26. apiCache = createMMKV({
  27. id: `api_cache`,
  28. path: `${RNFS.CachesDirectoryPath}`,
  29. });
  30. }
  31. return apiCache;
  32. }