简体   繁体   English

清除 glide 图片缓存 Android Studio

[英]Clear glide image cache Android Studio

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,请帮助我知道是否有任何方法可以清除此 slider object 的图像缓存,我必须每天更新图像,使用相同的链接,但glide正在缓存图像,

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.我之前使用过imageViewglide并且glide确实有一个缓存清理方法但是对于这个 object,我无法使用它。 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);
    
        }
    
    }

I can't see any of Glide related code in your code showed there.我在那里显示的代码中看不到任何与 Glide 相关的代码。

At least in my app, I use clearDiskCache method to clear Glide's disk cache.至少在我的应用程序中,我使用clearDiskCache方法来清除 Glide 的磁盘缓存。

Glide.get(context).clearDiskCache();

For clearing glide's disk cache, there is a clearDiskCache() method which will clear out all the cached items in the disk cache.对于清除 glide 的磁盘缓存,有一个clearDiskCache()方法可以清除磁盘缓存中的所有缓存项。

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.为了清除 glide 的 memory 缓存,有一个clearMemory()方法可以清除 memory 中的所有缓存项。

It must be called on the main thread.它必须在主线程上调用。

Glide.get(context).clearMemory();

Glide recommends not using clearMemory() very often. Glide 建议不要经常使用clearMemory()

Clearing all memory isn't particularly efficient and should be avoided whenever possible to avoid jank and increased loading times.清除所有 memory 并不是特别有效,应该尽可能避免,以避免卡顿和增加加载时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM