java Glide v4 中的 DiskCacheStrategy 差异
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46349657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference DiskCacheStrategy in Glide v4
提问by Priya
I am using Glide 4.1.1 in one of my android application. I am using it with below code and not facing any issue in application.
我在我的一个 android 应用程序中使用 Glide 4.1.1。我在下面的代码中使用它并且在应用程序中没有遇到任何问题。
Glide.with(context)
.load(constant.BASE_URL+"images/"+data.getPicture())
.apply(new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.dontAnimate()
.centerCrop()
.dontTransform())
.into(holder.imageView);
I have doubt in .diskCacheStrategy(DiskCacheStrategy.ALL) Option. There total five type option located with this like below
我对 .diskCacheStrategy(DiskCacheStrategy.ALL) 选项有疑问。共有五种类型选项,如下所示
.diskCacheStrategy(DiskCacheStrategy.ALL)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
I have tried to find its documentation but not able to find difference between this. Let me know if someone have used it and have idea what is difference between this all and when should we use it. Thanks
我试图找到它的文档,但无法找到它们之间的区别。让我知道是否有人使用过它并知道这一切之间的区别以及我们应该何时使用它。谢谢
回答by Yohannes Gebremariam
- Glide 3.x & 4.x: DiskCacheStrategy.NONE caches nothing
- Glide 4.x: DiskCacheStrategy.DATA, Glide 3.x: DiskCacheStrategy.SOURCE caches only the original full-resolution image.
- Glide 4.x: DiskCacheStrategy.RESOURCE Glide 3.x: DiskCacheStrategy.RESULT caches only the final image, after reducing the resolution (and possibly transformations) (default behavior of Glide 3.x)
- Glide 4.x only: DiskCacheStrategy.AUTOMATIC intelligently chooses a cache strategy based on the resource (default behavior of Glide 4.x)
- Glide 3.x & 4.x: DiskCacheStrategy.ALL caches all versions of the image
- Glide 3.x & 4.x:DiskCacheStrategy.NONE 不缓存任何东西
- Glide 4.x: DiskCacheStrategy.DATA, Glide 3.x: DiskCacheStrategy.SOURCE 只缓存原始的全分辨率图像。
- Glide 4.x: DiskCacheStrategy.RESOURCE Glide 3.x: DiskCacheStrategy.RESULT 在降低分辨率(和可能的转换)后仅缓存最终图像(Glide 3.x 的默认行为)
- 仅限 Glide 4.x:DiskCacheStrategy.AUTOMATIC 根据资源智能选择缓存策略(Glide 4.x 的默认行为)
- Glide 3.x & 4.x: DiskCacheStrategy.ALL 缓存所有版本的图像
Further Read this
进一步阅读本