【发布时间】:2016-02-12 10:02:28
【问题描述】:
我正在创建一个投票应用程序,每个投票都会有一个特定主题的相关图像。
我正在使用 Firebase 在事件发生时动态更新投票。在 Firebase 中,我存储了相关的图像 URL(引用 Amazon S3 中的 URL),然后我使用 Picasso 将图像加载到客户端的设备上(参见下面的代码)。
我已经注意到我处理这些数据的效率可能很低,导致对我在 S3 中的 Amazon 文件的不必要的 Get 请求。我想知道毕加索有什么选择(即我正在考虑一些缓存)来为每个客户端提取一次图像并将它们存储在本地(但是我不希望它们永久保留在客户端的设备上)。我的目标是最小化成本但不影响性能。以下是我当前的代码:
mPollsRef.child(mCurrentDateString).child(homePollFragmentIndexConvertedToFirebaseReferenceImmediatelyBelowDate).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int numberOfPollAnswersAtIndexBelowDate = (int) dataSnapshot.child("Poll_Answers").getChildrenCount();
Log.e("TAG", "There are " + numberOfPollAnswersAtIndexBelowDate + " polls answers at index " + homePollFragmentIndexConvertedToFirebaseReferenceImmediatelyBelowDate);
addRadioButtonsWithFirebaseAnswers(dataSnapshot, numberOfPollAnswersAtIndexBelowDate);
String pollQuestion = dataSnapshot.child("Poll_Question").getValue().toString();
mPollQuestion.setText(pollQuestion);
//This is where the image "GET" from Amazon S3 using Picasso begins; the URL is in Firebase and then I use that URL
//with the Picasso.load method
final String mImageURL = (String) dataSnapshot.child("Image").getValue();
Picasso.with(getContext())
.load(mImageURL)
.fit()
.into((ImageView) rootView.findViewById(R.id.poll_image));
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
【问题讨论】:
标签: amazon-web-services amazon-s3 firebase picasso