Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6208

How can I cache the getDownloadUrl() calls on the client with Firebase Firestore?

$
0
0

I store some Firebase Storage paths for images/videos in the backend DB and the mobile client uses these to fetch the download URLs as/when needed for my views:

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();
};

The problem is that I need the same image at many places. Hence I frequently call getDownloadURL() to retrieve the very same download Url. This results in the handset making multiple http requests for the same resource as it appears when I debug the network traffic.

I am not storing the retrieved download URLs in the mobile client anywhere in my current implementation.

I would like to find a way for the app to fetch the download URL only once for the same path and cache it. Is this supported by the Firebase SDK?


Viewing all articles
Browse latest Browse all 6208

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>