Volley : Image Caching
Asked Answered
S

1

7

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!

Slapbang answered 16/10, 2013 at 6:46 Comment(1)
I am also confused about this: https://mcmap.net/q/430734/-android-volley-imageloader-bitmaplrucache-parameter where it is said that ' Volley implicitly handles disk based cache in its own L2 cache. The image cache is just the L1 cache'Slapbang
L
15

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.

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.

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.

Laconic answered 20/10, 2013 at 16:45 Comment(3)
Thanks Itai! Like as you said I am not sure that the images which I am or any user (who will use this) will have cache headers or not. Thus I am trying to do force Disk caching only and for that I referred to: github.com/JakeWharton/DiskLruCache but I am not use whether this is a good way or any other approach may be better. Also I am not clear with whether I may use DiskBasedCache of volley hereSlapbang
Be careful: you do not want to use a disk cache where a memory cache is expected in the ImageLoader constructor. If you want to force caching you have to do exactly that - edit the Volley source code to either parse every HTTP header like it had a cache-header or change the check for entries in the cache. Also, if my answer helped, I'd appreciate it if you accept it, thanks.Laconic
Ok. Actually I was not aware that a memory cache is expected in ImageLoader. I missed on the reference which says that the passed cache should be 'The cache to use as an L1 cache'. And L1 obviously would be a memory one (correct me if I am wrong ;-)).Slapbang

© 2022 - 2024 — McMap. All rights reserved.