How to clear the cache of Addressables.DownloadDependenciesAsync()

We have a custom AsssetBundleProvider which downloads the bundles form remote and safes bundles to files.
We also have an option to clear that files.

When the user downloads a bundle, then clears the files and then tries to reload the bundles, the Addressables.DownloadDependenciesAsync() method does not use the AsssetBundleProvider but provides the bundle from its own cache or something.
For the user the bundle is now loaded and he can use it. But since our AssetBundleProvider is not used the files are not written and when the user restarts the app he has to redownload the bundle.

How can I disable that Addressable-Cache or clear it?

I allready tried:

  • Addressables.ClearDependencyCacheAsync(key); → that is mentioned in the documentation, but had no effect in my case

  • AssetBundle.UnloadAllAssetBundles() → Since in the documentation “Downloaded AssetBundles are stored in the engines AssetBundle cache” is mentioned. That also made no change

  • Uncheck “Use Asset Bundle Cache” in the Addressables Group Settings → no change

The documentation mentions “CacheInitializationSettings”, but I don’t know how that might help.

What did I miss?
How can I unload the bundle or clear that cache?

Can no one help me with thar?

Let me raise this with the team for a bit of guidance. :slight_smile:

There is an option in the group settings to disable the caching system. The CacheInitializationSettings object is an asset that you can create in your project to control the global cache settings of your application. Once you create the asset you would then add it to the Initialization Objects array in the may Addressables settings.

Thx I will try that out!

I tried it out, and it didn’t solve the problem. And in my initial post I mentioned that option too, so I tried it then, too. :slight_smile:

I looked a bit closer into it:
The option to disable the caching system has effect that the AssetBundleProvider always downloads the the file and does not cache it on harddrive. But that provider is not used, when you call Addressables.DownloadDependenciesAsync() for the second time.

We have a custom AssetBundleProvider which uses a different WebRequest System, since the UnityWebRequest does not support Proxys.
So from debug outputs I know that only the first time that Provider is used to download the file, the second time I is just there. So it seems to me that the addressables system writes the bundle into the RAM somewhere and uses it until the app is closed. So when I clear our download-Cache and try to reload it again, the bundles are provifed from there and our AssetBundleProvider is not used. But it is the one resonsible for the caching on file.

Hi, this sounds like you are not releasing the handle.
DownloadDependenciesAsync returns an AsyncOperationHandle. This counts as a reference to the AssetBundle, so when you use it. It will always have a reference count and not unload until that handle is released. Or until closing the app ofc.

If you only want to download the bundles and not keep a reference to them and use them in the AsyncOperationHandle, then you should use autoReleaseHandle = true. By default this is false.
Or release the handle manually.
Without doing do, when you call DownloadDependencies the second time. It will provide you with the currently loaded into memory bundle, and increase the reference count.

1 Like

Ah that does work. Thank you!