user3756319
user3756319

Reputation:

Android lrucache

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.

Upvotes: 1

Views: 957

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93561

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.

Upvotes: 1

Related Questions