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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With