Can Android Volley (Google IO 2013) have a Bitmap cache for level one of cache and also a disk cache for level2. I am not clear on if this is an or choice or an either/or choice. Also wondering about performance of Disk cache vs Bitmap cache for images. I notice that the ImageLoader seems to take either a disk cache or a bitmap cache, but I have also read somewhere about it having a level1 and level2 caching ...
3 Answers
Volley, by default, caches everything on disk (L2) based http headers. If there are no cache or TTL headers available, no disk caching will occure.
You asked a question regarding caching which has an answer that'll help you understand here.
About the Bitmap Cache. In fact, the ImageLoader
class expects an implementation of the interface ImageCache
which should be a memory cache (L1). See this question.

- 1
- 1

- 8,540
- 5
- 45
- 65
-
actually its not really the same question. there is level1 and level2 of cache. Also it is certainly true that you can switch out bitmap cache for ImageLoader while still using the disk cache for other types of data right? – TestBest Aug 12 '13 at 23:03
-
I guess the question isn't the same but the answer is comprehensive enough to answer this. To sum it up, the answer is yes: the L2 disk cache in internal and managed by Volley. **Every** http response coming through the `RequestQueue` you're using will be cached by default according to its http caching headers. On the other hand, the `ImageLoader` expects *you* to implement a memory cache and supply it in its constructor. – Itai Hanski Aug 13 '13 at 06:30
Out of the box Volley has only disk cache (DiskBasedCache class), but you can provide yours (implement com.android.volley.Cache interface). There is no such term as "Bitmap cache" in Volley. All the data (bitmaps, texts, etc.) is cached on disk by default.

- 2,084
- 1
- 26
- 40
I know it is an old question, but I had the same problem and took me couple of days reading blogs, watching videos and scrolling up and down in Volley source code to finally figure it out. So for the future reference here is the thing in the clearest way to explain:
- Volley caches EVERY response unless the response explicitly says "no-cache" or "no-store" in its header. if so, it won't be cached otherwise it will be cached according to "max-age" of the response header.
- The caching system above makes sense 100% since a response wont be valid if server says so that makes you capable of setting expiration date for each response from server side (It is awesome).
- if you don't like the above caching method you can override the corresponding part of code in volley source code, but it is highly NOT-recommended
- All mentioned above is cached on Disk using LRU algorithm which makes it L2. so volley has built in L2 caching for EVERY request (including images)
- Disk cache is blocking I/O. so lets say user swipes your ListView very fast and images should load very quickly, but the I/O blocks your main thread and you see some annoying jumping while scrolling. Then a non-blocking (in-memory) L1 cache comes handy and as you can see it is just useful when dealing with images. OK then, there is no built in L1 cache in Volley but IF you want to use the ImageLoader you can code your own and bind it to the ImageLoader. (Don't bother, thousands are already available under LruBitmapCache name, just copy one)
- Conclusion: Set your server to send proper caching data for your responses (which is very easy) and define an LruBitmapCache for your ImageLoader in Volley and all is done. You will have L1 and L2 caches. if L1 failes volley checks L2 (disk) and if fails again it goes for the RPC.
Hope it helps

- 1,044
- 10
- 11