1
votes

Hello guys and thank you for your time.

It is the very first time I ask something, but I have been researching for a couple hours without any kind of success.

The thing is that my game uses admob mediation with unity ads and everything works like a charm. The only problem is that the advertisements get cached in the data folder of my android device and gets way too big after a couple days (beyond 50 mB). I researched how could I clear these cached files and I could not find any kind of clearing method such as destroy for interstitial and banner ads.

Of course I could manually delete all the cached files every time the user leaves the app but I would prefer a standard AdLib api method. Any clue guys?

1

1 Answers

0
votes

I finally came up with the following solution. It's not beautiful, nor Orthodox in my opinion. But it works.

I usually create a class by feature in Unity, so I added the following code to the CacheManager class.

void OnApplicationQuit() {
    ClearCache();
}

void ClearCache ()
{
    var info = new DirectoryInfo (Application.persistentDataPath);
    var fileInfo = info.GetFiles ();
    foreach (FileInfo file in fileInfo) {
        string name = file.Name;
        if (name.EndsWith (".mp4") || name.EndsWith (".jpg") || name.EndsWith (".png") || name.EndsWith (".jpeg")) {
            File.Delete (Application.persistentDataPath + Path.DirectorySeparatorChar + name);
        }
    }

Quick explanation: I delete from the files folder (/data/data/com.mypackage.myapp/files in android devices) all the cached ads before closing the app.

NOTE that this fits my solution but might not fit yours.