What's the difference between an app's cache and data directories?


#1

Hi!

I have an App which plays some videos, and users want to have the choice to “download” the videos for offline use.

Given this example https://github.com/florentroques/expo-download-and-play-video-example it seems when downloading an Assert you have two choices were your file is going to be download, apps data and cache.

What are the differences between them? I couldn’t find any documentation about this.

thanks!


#2

The cache directory may be automatically cleaned up by the OS.

Android docs:

When the device is low on internal storage space, Android may delete these cache files to recover space. However, you should not rely on the system to clean up these files for you. You should always maintain the cache files yourself and stay within a reasonable limit of space consumed, such as 1MB. When the user uninstalls your application, these files are removed.

https://developer.android.com/guide/topics/data/data-storage.html

iOS docs:

Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file. Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content. Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.

https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html


#3

Thanks Ide!!

So cache is volatile, and apps data is a persistent storage mode, even the OS clears the cache, right?


#4

Yes, that’s right. The OS may clear the cache unexpectedly.