hamdy
hamdy

Reputation: 23

save the pictures in the cache forever with Glide

I want to save the pictures in the cache as long as possible. You can suggest a code to do this process. Thank you.

Upvotes: 0

Views: 2665

Answers (3)

Alexander Maslew
Alexander Maslew

Reputation: 408

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);

Upvotes: 0

freeman
freeman

Reputation: 94

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);

Upvotes: 0

Amirhosein
Amirhosein

Reputation: 4446

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)

Upvotes: 2

Related Questions