1

I'm using JakeWharton's DiskLruCache with this implementation: Using DiskLruCache in android 4.0 does not provide for openCache method

I have two questions: Do I still have to perform the operations in a separate thread, or does JakeWharton handle that in his class? I briefly read through his class and the only time he performs operations on a separate thread is for evictions. So for example, should I be calling SimpleDiskLruCache(...) in a separate thread?

Also, what is an appropriate size for the disk cache? I know this is a open-ended, subjective question, but I'm curious to hear what others have used for caching bitmaps. I'm assuming this number should be specified in bytes?

Community
  • 1
  • 1
ynnadkrap
  • 258
  • 2
  • 11

1 Answers1

3
  1. The signature of the API is a hint that you should read/write from the Cache as if it's an interface to disk. So to answer your question more directly - yes, you should call get() and put() in a thread separate from the main looper.

  2. Always be sympathetic to the user, and don't take more than you need. An appropriate size will depend on the nature of your application. Are you caching a large number of small bitmaps, or a small number of large images? How often do the images change? Are you planning on using an in-memory cache alongside the disk cache? Thinking about these questions will help you come to an appropriate specification that can drive your decision. Alternatively, you can start with a small number (maybe 4mb) and use some logging and/or metrics to measure the amount of cache misses and tweak from there.

  3. Finally, you should specify the number in bytes. E.g.

    DISK_CACHE_SIZE = 1024 * 1024 * 16; // 16mb in bytes

klmprt
  • 651
  • 6
  • 7