我想用礼品做一个回收服务。一切都显示完美,但壁画不缓存礼物。在向下滚动回收再向上滚动之后,gif将再次加载。我想应该快一点装进去。以前我用过ION library。加载速度更快,没有缓存问题。我不得不更改lib,因为它在gif解码方面有一些问题,如here所述。当前的解决方案如下:

//for default initial in application class

Fresco.initialize(this);
//I have also tried to change DiskCacheConfig and ImagePipelineConfig params.
//Without any positive result

//for recyclerview on onBindViewHolder
GenericDraweeHierarchy hierarchy = holder.draweeView.getHierarchy();
Uri uri = Uri.parse(path);
hierarchy.setPlaceholderImage(R.drawable.img_bg);
Logger.e(check(uri) + " " + uri.toString());
DraweeController controller = Fresco.newDraweeControllerBuilder().setUri(uri)
            .setAutoPlayAnimations(true).build();
    holder.draweeView.setController(controller);

//for method which show cached uri images in imagepipeline
public static boolean check(Uri uri) {
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    return imagePipeline.isInBitmapMemoryCache(uri);
}
//... all the time log shows "false + gif url"

我没有看到任何关于不缓存动画图像的信息。有关于动画不支持的图像后处理的信息,但这是一切。如何正确缓存gif?
编辑:
它看起来像fresco缓存动画,因为对于重新加载的gif,下面的方法返回true。
public static boolean isImageDownloaded(Uri loadUri) {
    if (loadUri == null) {
        return false;
    }
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
            .getEncodedCacheKey(ImageRequest.fromUri(loadUri));
    return ImagePipelineFactory.getInstance().getMainDiskStorageCache().hasKey(cacheKey)
            || ImagePipelineFactory.getInstance().getSmallImageDiskStorageCache()
                    .hasKey(cacheKey);
}

最佳答案

为了让事情更清楚一点,fresco有3个缓存级别:
diskcache-保持图像文件的原始格式。(将要)
准确地说,如果在不完全支持webp的android版本上
在存储之前,图像可能会被转换成其他格式。)
encoded memory cache-以原始编码格式在内存中缓存图像。(图像保持为原始字节的字节数组
因为它们存储在磁盘上+一些额外的元数据。)
BitmapMemoryCache—内存缓存,主要由Android位图组成。位图是解码图像,每个像素占用32位
这比编码时要多得多。
很明显,取舍是空间和时间。可用内存有限,如果图像不在位图缓存中,则必须重新解码。此外,如果它也不在编码的内存缓存中,则必须从磁盘读取它,这也可能会很慢。
现在回到动画图像。这是一个已知的限制。动画图像不会以解码形式缓存,因为这会耗尽位图缓存(只需乘以num_frames*width*height*32bpp),并且单个动画图像可能会逐出缓存中的每个其他图像。相反,它们是按需解码的,只有下一个将要显示的两个帧保存在一个短期缓存中。
我们有一些改善动画的计划,虽然我不能提供任何时间估计。

07-24 09:49
查看更多