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

Clear cache? #47

Closed
lusiaold opened this issue Jun 3, 2017 · 1 comment
Closed

Clear cache? #47

lusiaold opened this issue Jun 3, 2017 · 1 comment

Comments

@lusiaold
Copy link

lusiaold commented Jun 3, 2017

Hi, I'm using your app to load images that are being changed on the server every few minutes and I'd like to load new ones. Unfortunately, when an image is loaded with this library, it is stored in the cache and you can't view new image. I'd suggest you to add something like bigImageView.useCache(false);. Currently, I'm using this code to clear cache, but it's not perfect, I guess... (cache clearing provided by the library would be better):

@Override
protected void onStop(){
    super.onStop();
}
@Override
protected void onDestroy() {
    super.onDestroy();
    try {
        trimCache(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
public static void trimCache(Context context) {
    try {
        File dir = context.getCacheDir();
        if (dir != null && dir.isDirectory()) {
            deleteDir(dir);
        }
    } catch (Exception e) {
    }
}
public static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }
        }
    }
    return dir.delete();
}
@Piasy
Copy link
Owner

Piasy commented Jun 3, 2017

You can use Glide/Fresco's API to clear cache, BIV use them to load image.

@Piasy Piasy closed this as completed Oct 2, 2017
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

2 participants