我想显示一个带有许多(远程)图片的列表视图。我试图使用Volley来完成这个任务。
Volley有些有效,但效果不够好。在ImageLoader.get中,Volley有以下代码:
final String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight);
// Try to look up the request in the cache of remote images.
Bitmap cachedBitmap = mCache.getBitmap(cacheKey);
if (cachedBitmap != null) {
// Return the cached bitmap.
ImageContainer container = new ImageContainer(cachedBitmap, requestUrl, null, null);
imageListener.onResponse(container, true);
return container;
}
然而,getCacheKey 生成的键如下:
/**
* Creates a cache key for use with the L1 cache.
* @param url The URL of the request.
* @param maxWidth The max-width of the output.
* @param maxHeight The max-height of the output.
*/
private static String getCacheKey(String url, int maxWidth, int maxHeight) {
return new StringBuilder(url.length() + 12).append("#W").append(maxWidth)
.append("#H").append(maxHeight).append(url).toString();
}
即它会将一些像宽度和高度之类的“元数据”附加到键上。
这个键永远不会产生命中,如果图像不在L1缓存中,它将在线获取。当图像在线获取时,它将保存在磁盘缓存中,但Volley仅使用URL(而不是其他内容)作为键来保存它。
这是预期的行为吗?我有什么遗漏的吗?