- Home /
How to know if UnityWebRequestAssetBundle.GetAssetBundle is using a cached bundle?
I am loading asset bundles using UnityWebRequestAssetBundle.GetAssetBundle() per the documentation. Supposedly it automatically handles caching (I pass in a version number). However, I'm not certain that my WebGL build is using cached bundles. Every time I refresh the app, it appears that it is downloading the bundles again, just based on how long it takes to load them. It could just be the amount of time the WebGL version takes to OPEN them even if cached, I don't know. Is there anything I can do to see that it's using bundles from the cache?
Answer by MacDx · May 30, 2018 at 05:32 PM
There is a Caching class with some static methods that are exactly what you need. Specifically the IsVersionCached method. Just keep in mind that the overload that uses a version int is deprecated and you should use a Hash128 instead.
Hope this helps!
Documentation: https://docs.unity3d.com/ScriptReference/Caching.IsVersionCached.html
Thanks. That could help me know if there is a cached version, but I'm still not sure whether that function I mentioned is actually USING a cached version. The documentation on that function doesn't seem to mention whether it caches and uses a cached version. Is there some logging that can be enabled or something?
I just re-read the documentation at https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequestAssetBundle.GetAssetBundle.html It does mention about caching actually, but only if you provide a version number or hash. So, I guess I will assume it's working.
For whoever is unsure if it works, it is definitely working. I was using UnityWebRequest API to make requests to an AWS S3 bucket only to find out (after I changed the version parameter) that Unity has been using cached versions of the asset bundles all along since the request returned 403 Forbidden :)