I want to save the pictures in the cache as long as possible. You can suggest a code to do this process. Thank you.
Asked
Active
Viewed 1,657 times
3 Answers
2
Glide uses memory and disk caching by default to avoid unnecessary network requests and offers methods to adapt the memory and disk cache behavior:
GlideApp
.with(context)
.load(//...)
.skipMemoryCache(false)
.into(imageView);
Glide will put all image resources into the memory cache by default. Thus, a specific call .skipMemoryCache( false ) is not necessary.if you deactivate memory caching, the request image will still be stored on the device's disk storage.
val requestOptions = RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL)
Glide.with(context).load(url).apply(requestOptions).into(imageView)

Amirhosein
- 4,266
- 4
- 22
- 35
-
thank you for answer i used this code is this code correct Glide.with(context) .load(DataCoupon.get(position).getImage_product()) .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) .into(holder.ImageProduct); – hamdy Jan 14 '21 at 06:21
-
it could be right and depends on your strategy. please if if the answer is useful for you, accept and vote up the answer. – Amirhosein Jan 14 '21 at 12:28
0
try this but i am not sure
Glide.with(context)
.load(constant.BASE_URL+"images/"+data.getPicture())
.apply(new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.dontAnimate()
.centerCrop()
.dontTransform())
.into(holder.imageView);

freeman
- 92
- 11
-
thank you for answer i used this code is this code correct Glide.with(context) .load(DataCoupon.get(position).getImage_product()) .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) .into(holder.ImageProduct); – hamdy Jan 14 '21 at 06:26
0
It should be possible using DiskCacheStrategy.RESOURCE
with skipMemoryCache
set to true
:
Glide.with(mContext)
.load("Your Image Url")
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop()
.placeholder(R.drawable.loading_indicator)
.skipMemoryCache(true)
.into(imgView);

Alexander Maslew
- 408
- 5
- 16