2013-03-19 39 views

回答

32

使用MemoryCacheUtils

MemoryCacheUtils.findCachedBitmapsForImageUri(imageUri, ImageLoader.getInstance().getMemoryCache()); 

对于一个图像,内存缓存可以包含多个位图(不同大小)。所以内存缓存使用特殊键,而不是图像URL。

+0

是的,工作,谢谢。 – FWeigl 2013-03-19 20:22:14

+0

@NOSTRA这不适合我。如果我使用: MemoryCacheUtil.findCachedBitmapsForImageUri(URL,ImageLoader.getInstance()); 它要求我要铸造,所以......这是正确的? MemoryCacheUtil.findCachedBitmapsForImageUri(URL,(MemoryCacheAware <字符串,位图>)ImageLoader.getInstance()); – cesards 2013-10-04 13:21:35

+0

修复了答案。 – NOSTRA 2013-10-04 22:57:12

2

应该MemoryCacheUtil 小号,所以你应该使用

MemoryCacheUtils.findCachedBitmapsForImageUri(imageUri, ImageLoader.getInstance().getMemoryCache()); 
1

有时候,使用通用图像装载机库时,总会有一个时间,加载需要一段时间来验证远程图像是否有已被加载到您的缓存中。要直接加载缓存文件,可以使用下面的方法来检查是否远程文件的本地副本已经作出:

File file = imageLoader.getDiscCache().get(url); 
if (!file.exists()) { 
     DisplayImageOptions options = new DisplayImageOptions.Builder() 
     .cacheOnDisc() 
     .build(); 
     imageLoader.displayImage(url, imageView, options); 
} 
else { 
     imageView.setImageURI(Uri.parse(file.getAbsolutePath())); 
} 

检查在这里enter link description here

1

我想你可以创建一个简单方法在您的实用程序类是这样的:

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; 
} 

,并使用它像:

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

对于磁盘缓存使用下面的代码

public static boolean isDiskCache(String url) { 
     File file = DiskCacheUtils.findInCache(url, ImageLoader.getInstance().getDiskCache()); 
     return file != null; 
} 
相关问题