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

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 GitHub - florentroques/expo-download-and-play-video-example: Expo video: downloading -> storing/caching -> playing 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!

1 Like

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.

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.

1 Like

Thanks Ide!!

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

1 Like

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

2 Likes