Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use app cache for caching #43

Open
jjfster opened this issue Jul 11, 2011 · 10 comments
Open

Use app cache for caching #43

jjfster opened this issue Jul 11, 2011 · 10 comments

Comments

@jjfster
Copy link

jjfster commented Jul 11, 2011

Droid-Fu uses the app data storage for caching images.

Any way to have it use the app's cache, so that users can manage (read: clear) the app cache without affecting settings, etc.?

@jjfster
Copy link
Author

jjfster commented Jul 11, 2011

I probably just don't understand this fully (of course), but now when diskCacheIsEnabled, the app grows large very quickly.

Thanks.

@gradha
Copy link

gradha commented Jul 12, 2011

How do you measure the disk cache size? I'm going to the app settings and finding the cache is near zero, even though I see in the logs messages like "DISK cache hit for xxx".

@mttkay
Copy link
Owner

mttkay commented Jul 12, 2011

You can specify where you want to write the files using the AbstractCache.DISK_CACHE_INTERNAL and AbstractCache.DISK_CACHE_SDCARD fields.

ImageLoader's ImageCache caches to SD by default, unless no SD card is available.

@jjfster
Copy link
Author

jjfster commented Jul 12, 2011

app cache is near zero because the cache is being registered in the app's data. This was my original question: How do we assign the cache to the app cache, so users can manage the cache in Manage Applications, and not have to delete the app data (which deletes all settings, databases, etc)?

@mttkay
Copy link
Owner

mttkay commented Jul 12, 2011

Hmmm, it actually should already do that. We use getApplicationContext().getCacheDir() to determine where to write cached files when DISK_CACHE_INTERNAL is requested as the caching mode. Here are the relevant parts:

public boolean enableDiskCache(Context context, int storageDevice) {
    Context appContext = context.getApplicationContext();

    String rootDir = null;
    if (storageDevice == DISK_CACHE_SDCARD
            && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        // SD-card available
        rootDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/"
                + appContext.getPackageName() + "/cache";
    } else {
        File internalCacheDir = appContext.getCacheDir();
        // apparently on some configurations this can come back as null
        if (internalCacheDir == null) {
            return (isDiskCacheEnabled = false);
        }
        rootDir = internalCacheDir.getAbsolutePath();
    }

...

I think there are actually helper functions for this nowadays, but we wanted to remain backwards compatible to Android 1.5. So to be honest: I'm not sure why this is not working, I'd have to debug this first.

@futtetennista
Copy link
Collaborator

@jjfster: I am not sure I get your question. Are you asking how is it possible to wipe the files in "/Android/data/package/cache/" when the user chooses the clear the cache from the Settings? If so I am not sure how to do that, I thought the Android OS took care of that but it doesn't. Moreover: I tried to clear data but even when after that the files in that directory are still there.

@jjfster
Copy link
Author

jjfster commented Jul 13, 2011

When the images are cached, they are cached to the app's data storage, not the app cache. When you go on your device to: Settings/Applications/Manage Applications/[your app], you can see that the app cache (the second item in the dialog to clear) does NOT grow, but the app data storage (the first item on the list to clear) DOES grow, when using Droid-Fu's abstract cache.
Therefore, Droid-Fu is not using the app cache, but the data storage location, at least as the Android OS sees it (regardless of where it stores the actual file, i.e., sdcard, etc.). I was just hoping to be able to cache to the app cache rather than app data storage, so that if users want to clear the cache, they can do that by selecting "clear cache," rather than selecting "clear data" (which clears all the settings, databases, etc.).
Hope this explains it a little more clearly.
I guess if I had to I could add my own cache management buttons to the app, but that seems a little sillly.
Thanks.

@mttkay
Copy link
Owner

mttkay commented Jul 14, 2011

Hm yeah that's definitely an issue if that's true. I remember vaguely that in one of the newer SDK versions Google added a standard helper function to get a reference to the standard app cache dir. However, these methods are unavailable before 2.2 or so, that's why we never used them.

@jjfster
Copy link
Author

jjfster commented Jul 15, 2011

Ok, so I did a little playing around. It looks like no matter what I do, getExternalCacheDir() does not participate in the "app cache" helper feature. The "app cache" is only used and recognizes cache that is in the getCacheDir() directory.

Pretty silly, but I thought I didn't quite understand how they were handling app cache, and I just proved it!. Oh well, unless I'm still missing something?

@mttkay
Copy link
Owner

mttkay commented Jul 18, 2011

Which API level was that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants