Check if Image is in Cache - Universal Image Loader

前端 未结 5 1921
醉梦人生
醉梦人生 2021-02-07 18:29

I guess the title says it all. I tried:

imageLoader.getMemoryCache().get(key); 

with the image uri as key, but it always return null

5条回答
  •  忘了有多久
    2021-02-07 19:08

    I think you can create a simple method in your utility class like this:

    public static boolean isImageAvailableInCache(String imageUrl){
        MemoryCache memoryCache = ImageLoader.getInstance().getMemoryCache();
        if(memoryCache!=null) {
            for (String key : memoryCache.keys()) {
                if (key.startsWith(imageUrl)) {
                    return true;
                }
            }
        }
        return false;
    }
    

    and Use it like:

       if(Utils.isImageAvailableInCache(imageUrl)){
    //
          }
    

提交回复
热议问题