带有滑动和缓存的 FirebaseUI

FirebaseUI with glide and cache

我不太明白 recyclerView 和 glide 在缓存信息和图像数据方面是如何工作的,所以我想知道是否有人可以提供帮助。

目前我将关于我的图像的元数据存储在实时数据库中。元数据有足够的信息可以进行存储引用并从数据库中提取正确的图像:

storageReference.child("users/uid/profile.png")

但是,我的问题是关于 firebaseUI 元素的:

Glide.with(this)
    .using(new FirebaseImageLoader())
    .load(storageReference)
    .into(imageView);

所以我将图像添加到我的 recyclerview 如下:

for (ProfileCard card : localDB.getAllCards()) {
   profileCards.add(1, card);
   adapter.notifyItemInserted(1);
}

现在每次我离开这个 activity 卡片所在的地方时,activity 显然都被摧毁了。在 class 的 onCreate 中再次调用 for 循环。所以当我做的时候adapter.notifyItemInserted(1); adapter会被调用,添加图片的glide函数会再次被调用

所以我的问题是,每次我销毁并重新创建 activity 然后在调用 glide 方法时再次添加卡片时,它是否会向存储桶发出请求以再次下载图像?如果不是会发生什么?如果图像存储在缓存中,这个缓存有多大?

非常感谢任何帮助

如果您通读 the project wiki on GitHub,您关于 Glide 的许多答案都可以得到解答。

当 Glide 获取图像时,它将缓存在本地内存和磁盘上。你可以configure the sizes of these caches。以下是文档中关于默认磁盘缓存大小的内容:

The internal cache factory places the disk cache in your application's internal cache directory and sets a maximum size of 250MB.

对于内存缓存:

Default sizes are determined by the MemorySizeCalculator class. The MemorySizeCalculator class takes into account the screen size available memory of a given device to come up with reasonable default sizes.

物是人非,屡建屡拆。这就是这些缓存存在的原因。