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?