How to cache images in Glide

前端 未结 3 466
死守一世寂寞
死守一世寂寞 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: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);
    

提交回复
热议问题