Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference DiskCacheStrategy in Glide v4

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.

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.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

like image 279
Priya Avatar asked Sep 21 '17 17:09

Priya


People also ask

What is Glide DiskCacheStrategy?

Disk Cache Strategies The default strategy, AUTOMATIC , tries to use the optimal strategy for local and remote images. AUTOMATIC will store only the unmodified data backing your load when you're loading remote data (like from URLs) because downloading remote data is expensive compared to resizing data already on disk.

What is signature in Glide?

@Yeung Glide automatically does caching and it should work as long as the URL is same or image data is not removed due to space limit. Using a signature key is a specific case where you want to have more control over caching.


1 Answers

  • 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

Further Read this

like image 136
Yohannes Gebremariam Avatar answered Oct 05 '22 15:10

Yohannes Gebremariam