Can Volley (Google IO 2013) have level1 LruBitmapImageCache and level2 DiskCache?

Can Android Volley (Google IO 2013) have a Bitmap cache for the first level cache, as well as a disk cache for level2. I do not understand if this is a choice or any option. It's also interesting to know about the performance of the disk cache and Bitmap cache for images. I noticed that ImageLoader seems to use either the disk cache or the cache file, but I also read about it somewhere with level 1 and level 2 caching ...

+4
source share
3 answers

Volley, by default, caches everything on disk (L2) based on http headers . If there is no cache or TTL headers, there will be no disk caching.

You asked a question about caching, which has an answer that will help you understand here .

About the bitmap cache. In fact, the ImageLoader class expects an implementation of the ImageCache interface, which should be a memory cache (L1). See this question .

+2
source

Out of the box, โ€œVolleyballโ€ has only a disk cache (DiskBasedCache class), but you can provide your own (implement the com.android.volley.Cache interface). There is no such term as "Bitmap cache" in Volley. All data (bitmaps, texts, etc.) By default, are stored on disk.

+1
source

I know this is an old question, but I had the same problem, and I spent a couple of days reading blogs, watching videos and scrolling up and down the Volley source code to finally figure it out. Thus, for future reference, this explains what can be explained:

  • Volley caches EVERY response, unless the response explicitly says "no-cache" or "no-store" in its header. if so, it will not be cached, otherwise it will be cached according to the "maximum age" of the response header.
  • The caching system above makes 100% sense since the answer will not be valid if the server says so that you can set an expiration date for each response from the server (this is awesome).
  • if you donโ€™t like the caching method described above, you can override the corresponding part of the code in the volley source code, but it is strongly NOT recommended
  • All of the above is cached on disk using the LRU algorithm, which makes it L2. therefore, volleyball built in L2 caching for EVERY request (including images).
  • The cache cache blocks I / O. so let's say the user quickly deletes your ListView, and the images should load very quickly, but I / O blocks your main stream, and you see some annoying jumps when scrolling. Then the non-blocking (in memory) L1 cache is useful, and, as you can see, this is just useful when working with images. So, Volley does not have an L1 built-in cache, but if you want to use ImageLoader, you can encode your own and link it to ImageLoader. (Donโ€™t worry, thousands are already available under the name LruBitmapCache, just copy them)
  • Conclusion Set up the server to send the correct caching data for your responses (which is very simple) and define LruBitmapCache for your ImageLoader in Volley, and you're done. You will have L1 and L2 caches. if L1 does not check the volleyball L2 (disk), and if it works again, it will be used for RPC.

Hope this helps

0
source

Source: https://habr.com/ru/post/1495647/


All Articles