Volley:图像缓存 [英] Volley : Image Caching

查看:64
本文介绍了Volley:图像缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来从事Volley和缓存工作的:P.尽管我已经阅读了许多文章,与Volley进行图像缓存有关的帖子,但我仍不清楚采用Volley进行图像缓存的最佳/首选方式.像磁盘缓存还是内存? Volley已经提供了哪些支持以及如何提供(与L1和L2缓存支持有关)? 在我的情况下,我使用NetworkImageView来填充要从网络中获取的图像的列表视图. 预先感谢!

I am new to work on Volley and on caching too :P. Though I have already gone through a number of articles & posts related to Image Caching with Volley but I am still not clear with the best/preferred way for Image Caching with Volley. Like disk caching or memory? What support does Volley already provide and how (related to L1 and L2 caching support)? I am using NetworkImageView in my case, to populate a list view with images to be fetched from net. Thanks in advance!

推荐答案

对于图像缓存,volley希望您为图像提供实现内存缓存.在应用程序正常运行期间使用此缓存,以加快使用内存的加载时间.

For image caching, volley expects you to provide an implementation memory cache for images. This cache is used during the up time of the app for quicker loading times using the memory.

与图像无关,Volley拥有自己的磁盘缓存,用于缓存每个响应,其默认策略是根据进行缓存缓存HTTP响应的标头.

Not related specifically to images, Volley has its own disk cache which it uses to cache EVERY response it gets, with the default strategy of caching according to cache headers of the HTTP response.

如果要在应用程序中加载的图像具有缓存头,则会根据它们在磁盘上对其进行缓存,否则不会.

If the images you are loading in your app have cache headers, they will be cached according to them on the disk, otherwise the will not be.

如果您对此策略不满意,并且想要强制磁盘缓存,则必须编辑/添加一些更改缓存策略的代码.有多种方法可以实现此目的,一种方法是提供您自己的实现来解析HTTP标头.看看Volley来源中的HttpHeaderParser.

If you're unhappy with this strategy and want to force disk caching, you'll have to edit / add a little code that changes the caching strategy. There are many ways to achieve this, one being providing your own implementation to parsing the HTTP headers. Take a look at HttpHeaderParser in the Volley source.

这篇关于Volley:图像缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆