gpt4 book ai didi

android - Fresco 未使用来自网络的图像更新磁盘缓存

转载 作者:行者123 更新时间:2023-11-29 01:31:22 25 4
gpt4 key购买 nike

我一直在尝试通过 Facebook 使用 Fresco 库。

从文档中我了解到,当我们使用 SimpleDraweeView 时,图像缓存与 ImagePipeline 开箱即用。尽管 Fresco 从我的 URI 中获取图像,但 DiskCache 和其他缓存中的图像并没有被它替换,我几乎看到一切都完美地工作。

我对获取图像的代码持肯定态度,因为在我清除缓存并实现了 RequestListenerControllerListener< 后,我的图像确实会在我第一次运行应用程序时显示 这两个结果都成功了。

这是我当前的设置:

// Setting the collaborator image.
GenericDraweeHierarchy collaboratorPicHierarchy =
genericDraweeHierarchyBuilder
.setPlaceholderImage(
getInitialsAsDrawable(
collaborator.getUser().getInitials()
)
)
.setRoundingParams(new RoundingParams()
.setRoundAsCircle(true)
)
.build();
holder.collaborator.setHierarchy(collaboratorPicHierarchy);
holder.collaborator.setImageURI(
Uri.parse(AltEngine.formURL("user/getProfilePic/") +
accessToken + "/" +
collaborator.getUser().getUuid()
)
);

所有这些代码都位于适配器内部,并且在适配器的构造函数中我已经初始化了 Fresco。

imagePipelineConfig = ImagePipelineConfig.newBuilder(this.context)
.build();
Fresco.initialize(this.context, imagePipelineConfig);

在 StackOverflow 中进行了大量搜索后,我发现可以使用以下代码段。

Fresco.getImagePipelineFactory().getMainDiskStorageCache().remove(new SimpleCacheKey(uri.toString()));
Fresco.getImagePipelineFactory().getSmallImageDiskStorageCache().remove(new SimpleCacheKey(uri.toString()));

我在与 SimpleDraweeView 关联的 ImageRequest 实例的 onRequestSuccess 中进行了尝试,但这导致每次刷新时都会显示占位符ListView 不好。

我找到的下一个解决方案来自这里 Android - How to get image file from Fresco disk cache?这表明可能有必要为 Fresco 实现我自己的 DiskCacheConfig 以使我的 DiskCache 无效,因此我尝试使用我在 SO 问题中找到的代码配置我的 DiskCache。

DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder().setBaseDirectoryPath(this.context.getCacheDir())
.setBaseDirectoryName("v1")
.setMaxCacheSize(100 * ByteConstants.MB)
.setMaxCacheSizeOnLowDiskSpace(10 * ByteConstants.MB)
.setMaxCacheSizeOnVeryLowDiskSpace(5 * ByteConstants.MB)
.setVersion(1)
.build();
imagePipelineConfig = ImagePipelineConfig.newBuilder(this.context)
.setMainDiskCacheConfig(diskCacheConfig)
.build();
Fresco.initialize(this.context, imagePipelineConfig);

缓存仍然没有被来自网络的图像更新。

我不知道这里出了什么问题。可能是我把 Fresco 弄错了。无论如何我被困在这里并且不知道如何进行。我已经看过几次文档,由于运气不好,我可能错过了一些重要的东西。请指出正确的方向。

最佳答案

这基本上与此处提出的问题相同:https://github.com/facebook/fresco/issues/124 .

事实上,您在上面粘贴的两行中关于从磁盘缓存中删除的想法是正确的。你只需要在正确的地方调用他们。 onRequestSuccess 不是正确的位置,因为它会破坏您刚刚下载的图像。

您希望在 之前从缓存中删除旧条目,甚至发送新条目请求。如果 Fresco 在磁盘上找到图像,它甚至不会发出网络请求。

关于android - Fresco 未使用来自网络的图像更新磁盘缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31030149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com