Reference

getCacheDir()

getCacheDir() returns the app's private internal cache directory on Android. Files there are app-owned, count as the app's cache in Settings, and the system can auto-delete them under low storage. The OS also wipes them when the app is uninstalled.

Android developmentAndroid

getCacheDir()

Also known as: android getcachedir, Android cache directory, internal cache dir, Context.getCacheDir

getCacheDir() returns the app's private internal cache directory on Android. Files there are app-owned, count as the app's cache in Settings, and the system can auto-delete them under low storage. The OS also wipes them when the app is uninstalled.

  • Lives at /data/data/<package>/cache inside the app's private sandbox.
  • The system can auto-delete it under low storage and wipes it on uninstall.
  • It is exactly what Settings > Storage > Clear cache removes.

What getCacheDir() returns

Context.getCacheDir() returns a File pointing to a per-app cache folder inside internal storage, typically at /data/data/<package>/cache (surfaced as /data/user/0/<package>/cache on modern multi-user builds). No runtime permission is needed because the directory belongs to your app's sandbox, and no other app can read it.

Anything written here is treated by the platform as disposable. When internal storage runs low, Android can delete cache files on its own, with no callback to your app, so code must never assume a cached file still exists. The space is also reported as Cache under Settings > Apps > <app> > Storage and is what the system clears when the user taps Clear cache.

How it differs from files and external cache

Use getCacheDir() for regenerable data: decoded thumbnails, network responses, transient scratch files. Use getFilesDir() for data that must persist, since the system never auto-evicts it. For larger or media-style caches you can fall back to getExternalCacheDir(), which lives on external storage but is still app-private and uninstall-cleaned.

Google recommends keeping the cache modest (the platform guidance suggests staying around 1 MB for the internal cache) and pruning old entries yourself rather than relying on the OS. Reading the cache size at runtime is done with StorageStatsManager or by walking the directory; clearing it is just deleting the files.

Why it matters for a storage cleaner

The bytes a cleaner like Cleanor reports as clearable app cache come straight from these directories. Clearing an app's cache removes the contents of getCacheDir() (and getExternalCacheDir()) without touching saved files, accounts, or settings, which is why it is the safest first step to free up space.

Because the OS may already be reclaiming this space during pressure, a good cleaner shows the current cache footprint, lets the user clear it on demand, and never deletes anything from getFilesDir() in the process.

Related terms

Keep reading the reference.

Act on it

Guides and tools for this topic.