Persistent Image Caching

988 views
Skip to first unread message

Fahim Farook

unread,
May 21, 2013, 6:30:05 PM5/21/13
to volley...@googlegroups.com
Perhaps I've misunderstood how the ImageLoader class works but based on the Google I/O session (and a brief look through the code) I was under the impression that images are cached by a caching class which implements the ImageCache interface. Is this correct?

Or is image caching handled by the underlying RequestQueue and all image requests are cached to disk anyway as long as the RequestQueue has a disk cache assigned to it?

I've been trying to clarify this point for a bit now but so far haven't gotten a satisfactory response :)

My basic need here is to cache images for a list of articles so that: a) the user has access to those images even if they are offline b) the article list loads fast the second time they access it since most of the images would have been cached. So far have not had a great deal of success with NetworkIMageView to do this consistently. If I use a basic LruCache as mentioned in the Google I/O session, the images load sometimes and sometimes they don't and they are always fetched again from the server if needed. There appears to be no caching of the images.

Ficus Kirkpatrick

unread,
May 21, 2013, 6:46:14 PM5/21/13
to Fahim Farook, volley...@googlegroups.com
Requests are cached to disk, including image requests. The purpose of ImageCache (and indeed, ImageLoader) is to provide an L1 in-memory cache for quickly handling things like screen rotation and nearby scrolling.

You cannot use Volley to load from somewhere other than the network.

Ficus




--
You received this message because you are subscribed to the Google Groups "Volley Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to volley-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Fahim Farook

unread,
May 21, 2013, 6:53:50 PM5/21/13
to volley...@googlegroups.com, Fahim Farook
When you say "You cannot use Volley to load from somewhere other than the network." does that include fetching previously cached images if you are offline?

Christoph Studer

unread,
May 21, 2013, 6:54:28 PM5/21/13
to Fahim Farook, volley...@googlegroups.com
Some more details inline (received Ficus' response while I was typing this :-)).

On Tue, May 21, 2013 at 3:30 PM, Fahim Farook <fah...@gmail.com> wrote:
> Perhaps I've misunderstood how the ImageLoader class works but based on the
> Google I/O session (and a brief look through the code) I was under the
> impression that images are cached by a caching class which implements the
> ImageCache interface. Is this correct?
>
> Or is image caching handled by the underlying RequestQueue and all image
> requests are cached to disk anyway as long as the RequestQueue has a disk
> cache assigned to it?

This is correct. All HTTP responses, including images, are
automatically cached by Volley if the cache headers allow for it.

The cache in ImageLoader serves a different purpose: It keeps bitmaps
in RAM such that you can populate the UI without:
1. A round-trip to the network or disk
2. Image decoding

This allows for flicker-free, synchronous UI population from the UI
thread (if the image is in cache), with a fallback to disk cache or
network when necessary.

> I've been trying to clarify this point for a bit now but so far haven't
> gotten a satisfactory response :)
>
> My basic need here is to cache images for a list of articles so that: a) the
> user has access to those images even if they are offline b) the article list
> loads fast the second time they access it since most of the images would
> have been cached. So far have not had a great deal of success with
> NetworkIMageView to do this consistently. If I use a basic LruCache as
> mentioned in the Google I/O session, the images load sometimes and sometimes
> they don't and they are always fetched again from the server if needed.
> There appears to be no caching of the images.

You can't use Volley for offline-access, that's not what it's designed
for. Its caches aren't offline storage, entries can be evicted at any
time.

If you see a lot of cache misses, check that:
1. The images are in fact cacheable, i.e. the server responds with
appropriate HTTP cache headers.
2. You have a unique URL for images.
3. The disk cache of your RequestQueue has a large enough disk quota.

Enabling VERBOSE logging for Volley should help you see what's going
on. With a device / emulator connected:

'adb shell setprop log.tag.Volley VERBOSE'

Then run through the app and watch logcat for Volley messages.

Christoph

Fahim Farook

unread,
May 21, 2013, 7:02:43 PM5/21/13
to volley...@googlegroups.com, Fahim Farook
Thanks for the detailed response, Christoph :) You also answered my previous question about offline access, so I think that clarifies everything.

I did use VERBOSE logging to check on the image requests. That's how I knew they were hitting the network rather than getting the images from the cache. But it sounds as if Volley won't work for what I have in mind for this particular app. I'm already using a different image caching library in the app but I was hoping that I could replace it with Volley since I'm already using Volley for HTTP requests. But guess I'll just have to stick with the two separate libraries.

Thanks again :)
Message has been deleted

Huteri Manza

unread,
May 22, 2013, 10:24:12 PM5/22/13
to volley...@googlegroups.com, Fahim Farook
Hi, I got what you mean here. I experienced it by myself, volley could not use cached images by another reference. I'm sorry to late understand this. Can I know what library do you use to caching images?

Fahim Farook

unread,
May 22, 2013, 10:30:53 PM5/22/13
to volley...@googlegroups.com, Fahim Farook
I use Universal Image Loader:


It works pretty well for what I need done. I was hoping that I could drop it and switch to Volley since I'd prefer to have some of the priority functionality that Volley provides for requests. But guess not, at least for the time being :)

Regards,

Fahim

Waseem Sakka

unread,
Dec 3, 2013, 10:31:59 AM12/3/13
to volley...@googlegroups.com, Fahim Farook
If you want persistent image caching, UIL is more suited for that than Volley. 
Reply all
Reply to author
Forward
0 new messages