Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When would you save data to the internal cache directory?

I am reading through the Android developer docs on saving data and they mention that when saving a file to internal storage you can use either getFilesDir() or getCacheDir(). When would it be appropriate to save to the cache directory, and what type of data is best saved here?

like image 241
young_souvlaki Avatar asked Sep 25 '22 09:09

young_souvlaki


1 Answers

Use the cache directory to save temporary files. For example, if you're writing a social app (like instagram) and during runtime the app loads user's pictures, you can store those pictures on the cache directory, so if the user resumes the app while offline, he will still be able to see the last pics.

Make sure to delete each file once it is no longer needed and implement a reasonable size limit for the amount of memory you use at any given time, such as 1MB.

like image 114
Rosário Pereira Fernandes Avatar answered Oct 11 '22 05:10

Rosário Pereira Fernandes