Home > Enterprise >  Clear glide image cache Android Studio
Clear glide image cache Android Studio

Time:09-27

Please help me to know if there is any way to clear the image cache of this slider object, I have to update the image every day, using the same link, but the glide is caching the image,

I've used glide with an imageView earlier and glide does have a cache clean method but with this object, I'm not able to use it. thanks in advance.

package com.xperiaplayy1.LoteriaPanamaEnVivo;
    
    import android.os.Bundle;
    import android.widget.ImageView;
    
    import androidx.appcompat.app.AppCompatActivity;
    import androidx.recyclerview.widget.RecyclerView;
    
    import com.bumptech.glide.Glide;
    import com.bumptech.glide.load.engine.DiskCacheStrategy;
    import com.bumptech.glide.request.RequestOptions;
    import com.denzcoskun.imageslider.ImageSlider;
    import com.denzcoskun.imageslider.models.SlideModel;
    
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    
    
    
    
    public class Slider extends AppCompatActivity {
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_image_slider);
            ImageSlider imageSlider = findViewById(R.id.slider);
            List<SlideModel>slideModels = new ArrayList<>();
            slideModels.add(new SlideModel("https://www.codeproject.com/KB/testing/1002904/Test-URL-Redirects-HttpWebRequest.jpg","Piramide 1"));
            slideModels.add(new SlideModel("https://shortpixel.com/img/robot_lookleft_wink_big.png","Piramide 2"));
            slideModels.add(new SlideModel("https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/1200px-Image_created_with_a_mobile_phone.png","Piramide 3"));
            slideModels.add(new SlideModel("https://static.remove.bg/remove-bg-web/8fb1a6ef22fefc0b0866661b4c9b922515be4ae9/assets/start_remove-c851bdf8d3127a24e2d137a55b1b427378cd17385b01aec6e59d5d4b5f39d2ec.png","Piramide 4"));
            slideModels.add(new SlideModel("https://media.istockphoto.com/photos/colored-powder-explosion-abstract-closeup-dust-on-backdrop-colorful-picture-id1072093690?k=20&m=1072093690&s=612x612&w=0&h=Ns3WeEm1VrIHhZOmhiGY_fYKvIlbJrVADLqfxyPQVPM=","Piramide 5"));
            imageSlider.setImageList(slideModels,true);
    
        }
    
    }

CodePudding user response:

I can't see any of Glide related code in your code showed there.

At least in my app, I use clearDiskCache method to clear Glide's disk cache.

Glide.get(context).clearDiskCache();

CodePudding user response:

For clearing glide's disk cache, there is a clearDiskCache() method which will clear out all the cached items in the disk cache.

It must be called on a background thread.

   Glide.get(context).clearDiskCache();

For clearing glide's memory cache, there is a clearMemory() method which will clear out all the cached items from the memory.

It must be called on the main thread.

Glide.get(context).clearMemory();

Glide recommends not using clearMemory() very often.

Clearing all memory isn’t particularly efficient and should be avoided whenever possible to avoid jank and increased loading times.

  • Related