JakeWharton/DiskLruCache — Issue #2: Android aggresive cache clearing leads to crash
Author: lexs
Created: 2012-01-08 22:21:32+00:00
State: open

I have the cache put inside a subdirectory in the application cache directory. On devices with low internal storage (Nexus One for example) this will eventually lead to low storage situations where Android will just clear the whole cache directory, including subdirectories.

This gives this:
java.io.FileNotFoundException: /data/data//cache/images/-1944396650.0.tmp (No such file or directory)
at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
at java.io.FileOutputStream.(FileOutputStream.java:94)
at java.io.FileOutputStream.(FileOutputStream.java:66)
at .DiskLruCache$Editor.newOutputStream(DiskLruCache.java:686)

It's thrown because the images directory is now gone. I though listening for ACTION_DEVICE_STORAGE_LOW could solve this but that is broadcasted after Android has cleared the directory.

If would be nice if it was possible to just reset the cache when the whole directory has gone missing or something.