How to cache images in Glide

前端 未结 3 462
死守一世寂寞
死守一世寂寞 2020-12-20 16:50

When I use glide, some images doesn\'t loads. How can I store it in the cache, or anywhere, to when I\'ll use the app all my images loads. Example picture of my problem:

相关标签:
3条回答
  • 2020-12-20 17:22

    Glide will put all image resources into the memory cache by default. Thus, a specific call .skipMemoryCache( false ) is not necessary.

    Hint: beware of the fact, that if you make an initial request to the same URL without the .skipMemoryCache( true ) and then with the method, the resource will get cached in memory. Make sure you're consistent across all calls to the same resource, when you want to adjust the caching behavior!

    Referance: https://futurestud.io/tutorials/glide-caching-basics

    0 讨论(0)
  • 2020-12-20 17:30

    Please Read the Description below as per official documentation : https://futurestud.io/tutorials/glide-caching-basics

    0 讨论(0)
  • 2020-12-20 17:34

    Here is a common scenario you want to load image from the cache and download the new data only if a new image exist , you have to have a way to know if the image is updated ,for example a variable called imageTimeStamp containing the last time the image was updated.

                Glide.with(context).load(url).apply(new RequestOptions()
                    .placeholder(R.drawable.defultIcon)
                    .signature(new ObjectKey(image.getPPTimeStamp()))) // here you add some value , if the next time you add the same value then it will load from cache otherwise if you put new value you will download , then save in cache
                    .into(icon);
    
    0 讨论(0)
提交回复
热议问题