如何使用Firebase Firestore在客户端上缓存getDownloadUrl()调用?

问题描述 投票:0回答:1

我在后端数据库中存储了一些用于图像/视频的Firebase存储路径,并且移动客户端使用这些路径来获取下载URL作为/当需要查看时:

import {firebase} from '@react-native-firebase/storage';

// e.g. 'images/stars.jpg'
const getDownloadUrlForFilePath = (filePath: string | null): Promise<string> => {
  if (filePath === null) {
    throw 'Path is null!';
  }
  return getDownloadUrlForRef(firebase.storage().ref(filePath));
};

const getDownloadUrlForRef = (ref): Promise<string> => {
  return ref.getDownloadURL();
};

问题是:我在很多地方都需要相同的图像,因此经常调用getDownloadURL()来检索相同的下载网址。这导致手机对我调试网络流量时出现的资源发出多个http请求。 我想为该应用找到一种方法,可以为同一路径仅获取一次下载URL并对其进行缓存。 Firebase SDK支持此功能吗? (在当前实现的任何地方,我都不会在移动客户端中存储检索到的下载URL。)

firebase react-native google-cloud-firestore google-cloud-storage react-native-firebase
1个回答
0
投票

您可以使用AsyncStorage将URL本地保存在App上,而无需发出HTTPS请求以及在App的任何组件上就可以获取这些URL。

© www.soinside.com 2019 - 2024. All rights reserved.