How can I get informations within code about the cache of my app?

user3890967

I want to check where my apps cache is raising all the time. So I need a method to access informations about the current cache at any time. I think there must be such a method, because I could see the size of the cache in the App-Info of my android-smartphone. The app is running in the background and I want to log when the size of the cache is raising.

Android Team

Use below code snippets for your solution.

public static byte[] retrieveData(Context context, String name) throws IOException {

        File cacheDir = context.getCacheDir();
        File file = new File(cacheDir, name);

        if (!file.exists()) {
            // Data doesn't exist
            return null;
        }

        byte[] data = new byte[(int) file.length()];
        FileInputStream is = new FileInputStream(file);
        try {
            is.read(data);
        }
        finally {
            is.close();
        }

        return data;
    }

Here is complete CacheManager class.

When to clear the cache dir in Android?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Can I use WebAssembly to safely execute untrusted user code within my web app?

How do I get maven managed dependencies copied into war\web-inf\lib so I can run my GWT 2.0 app in debug mode within Eclipse?

How can I get my code to return the correct variable?

How can I get information about the file that launched my app?

How can I get this App Store purchase window in my app?

How can I get my firebase listener to load data to my redux state in a React Native app so I can read the data within my ComponentDidMount function?

How can I get the number of online users now in my app

How can I get the deployment name from within my container?

on Heroku how can I get the current release number of my app

How can I get prometheus exporters running in my grails app?

How can I get GPG Agent to cache my password?

How can I get my code to stop in Visual Basic?

How can I get the font names bundled in my iOS app?

How can i get my php source code length?

Can I tell within application code, on what outermost port of my server the app is accessed?

Error within my code how can I centre responsive image?

How can I see if my password variable is within a line so that my code can proceed?

How can I transform my code to get a dropbox instead of text?

How can i get value from an Rxjs observable in my code?

How can I get my app screen time on a hourly basis?

How can I get my AdRotator ads to stay within the div?

How do i Whitelist my app for Huawei Smartphones within the code?

How would I go about creating an app that can change python code from within the app?

How can I get my code to restart based on user input?

How can I edit my code on CPLEX about tuple?

How can I better get my searchbar within my nav to vertically center?

How can I get my iOS app connected with api?

How can I showcase the code snippets in my react app?

How can I update the "count" within my Kotlin app