Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When caching images and data should you use Internal or External Storage?

I've read this Android save app settings/data in Internal/External Storage but I don't think i've really got an answer.

I'm developing an app where I should store some "cache" data, like a dozen of images and some strings (json).

Initially I was storing all that on the sdcard, (external storage) but later i thought that this could be deprecated by the SDCard deprecation in most recent devices.

After reading a bit, I understood that external storage is not only sdcard, but "a removable storage media (such as an SD card) or an internal (non-removable) storage" so it should not be deprecated but...it's shared space, and there is not ownership over the files stored there, so the first problem was that I was unable to delete them when the app was deleted.

So I changed to the Internal Storage, to avoid having the files/images "public" and also having them removed after app deletion.

Is this the recommended approach?

On devices older with low internal storage but with a lot of space in the SDcard is this a good approach?

My application supports from 1.6 to 4.0 (so far) so I have a lot of legacy devices... and I must have the app working (well) on all.

Looking forward for some interesting answers!

like image 812
neteinstein Avatar asked Dec 16 '11 15:12

neteinstein


People also ask

When should I use an external cache?

Using an external cache allows you to overcome a few limitations of the built-in cache: Avoid having your cache periodically cleared during API Management updates. Have more control over your cache configuration. Cache more data than your API Management tier allows.

What should be stored in cache?

The data in a cache is generally stored in fast access hardware such as RAM (Random-access memory) and may also be used in correlation with a software component. A cache's primary purpose is to increase data retrieval performance by reducing the need to access the underlying slower storage layer.

Should I cache images?

Generally yes, images should be cached in at least memory, and depending on your app (how likely is it to be reused,etc) in memory and storage. If you want to support your 3rd point (displaying when offline), you need to do storage caching, and memory caching is optional but probably a good idea.

Does cache store images?

The bitmap cache stores decoded images as Android Bitmap objects. These are ready for display or postprocessing. On Android 4. x and lower, the bitmap cache's data lives in the ashmem heap, not in the Java heap.


1 Answers

I would keep images on the external storage, probably in a "hidden" folder (adding a dot at the beggining of the folder's name: .folder) and also a the Media Scanner "avoider" (.nomedia), because, as you pointed, you want the application to work in old devices, and precisely those devices don't have to much internal memory.

You can also add an option in your application to remove that folder, so in case the user wants to uninstall, he can do that before.

like image 84
SERPRO Avatar answered Oct 10 '22 19:10

SERPRO