1

I used the code android lrucache example (Memory Cache) to cache downloaded images(total nearly 120 kbytes) and it works, but when I go out from the activity(or app) the cache is removed, and when i again go to the activity it downloads and caches the images again.

Please tell me: if I can use lrucache to store data for nearly 5 days(nearly 1mb) or if can' t, can I do it using DiskLruCache? Thank you in advance.

1 Answers1

1

You may be able to do it with LRUCache, but it depends. If the LRUCache is a static variable, it will stick around even after your activity is destroyed so long as your app isn't killed by the framework. But if Android ever goes low on memory, it will kill it.

If you want to cache things for a long time, your best bet is a disk cache of some sort. In fact you can combine both for best results- a disk cache so you don't have to download new files, and an in memory cache for performance so you don't need to continually re-read them. They really focus on different areas.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Thank you very much for a very useful information. How should I make it static? Just writing in stead of private LruCache mMemoryCache; --> private static LruCache mMemoryCache; ? –  Jun 28 '14 at 09:00
  • Please answer to the previous question too, thank you. –  Jun 28 '14 at 09:19