Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Android aggresive cache clearing leads to crash #2

Closed
lexs opened this issue Jan 8, 2012 · 9 comments
Closed

Android aggresive cache clearing leads to crash #2

lexs opened this issue Jan 8, 2012 · 9 comments

Comments

@lexs
Copy link

lexs commented Jan 8, 2012

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/<package>/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.<init>(FileOutputStream.java:94)
at java.io.FileOutputStream.<init>(FileOutputStream.java:66)
at <package>.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.

@tonnguyen
Copy link

Hi Lexs,

Is it possible to write cache into a cache directory which is located in SD Card?(/mnt/sdcard/data/somepackagename/cache/images/)

In my opinion, Android would never clear this, and this could be a workaround.

@lexs
Copy link
Author

lexs commented Jan 9, 2012

Yes, this would work but will introduce other problems, for example that SD storage can be removed at any time or not even be available. I guess these issues could be worked around as well though.

@JakeWharton
Copy link
Owner

Give the dev branch a try. Threw in a quick sanity check and attempted directory recreation.

@JakeWharton
Copy link
Owner

Gerrit tracking: https://android-review.googlesource.com/31430

@lexs
Copy link
Author

lexs commented Jul 23, 2012

What happened to this? Should I still try dev? I'm asking as my image loader is based on this and when they user clicks "clear cache" in app info all new writes will fail if the app was open.

@JakeWharton
Copy link
Owner

It's fixed on dev but I didn't like the solution. Maybe @swankjesse can comment as to a better solution.

@swankjesse
Copy link
Collaborator

My original preference was for the cache to stop caching if ever it runs into a hostile storage system. But in @lexs scenario, that's probably to heavy-handed. It would probably be more robust for the cache tried its best to keep caching even as things disappeared out from under it.

That way, if a user clicks 'clear cache' while the app is open, performance won't degrade indefinitely.

@JakeWharton can you assign this to me? I'll code up a fix.

@ghost ghost assigned swankjesse Jul 23, 2012
@swankjesse
Copy link
Collaborator

Sadly I still haven't gotten around to doing this work. If you'd prefer to tackle it, it's all yours. Otherwise I'll circle back when I have time.

@JakeWharton
Copy link
Owner

New implementation of this on dev.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants