Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question About the cache mechanism of wasm.unityweb.

Discussion in 'Web' started by DavidWeng, Aug 10, 2023.

  1. DavidWeng

    DavidWeng

    Joined:
    Oct 15, 2022
    Posts:
    7
    Hello, I have a question, I exported the game to the WebGL platform and opened the game using the WebView for Android. I found that the file wasm.unityweb has cache if it's within 5MB, but no cache if it's more than 5MB and the file wasm.unityweb will be re-downloaded every time I start the game. But the file data.unityweb is about 10MB, but it has cached all the time, is it because the cache of data.unityweb is using IndexedDB while the cahce of wasm.unityweb is using LocalStorage? I checked the limit of LocalStorage is about 5MB, is there any way to make wasm.unityweb have a cache even if it is more than 5MB?

    The version of Unity I'm using is 2021.3.20f1.
     
    Last edited: Aug 15, 2023
  2. DavidWeng

    DavidWeng

    Joined:
    Oct 15, 2022
    Posts:
    7
    Last edited: Aug 15, 2023
  3. DavidWeng

    DavidWeng

    Joined:
    Oct 15, 2022
    Posts:
    7
    Does anyone else know about this problem?
     
  4. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    951
    Earlier versions of Unity utilize IndexedDB to implement caching of .wasm and .data files if "Data Caching" option is enabled. Later versions (off the top of my head, 2022.1 and newer, although don't quote me on that, my memory might be failing) updated to utilize the Cache API instead, which provides better performance than IndexedDB.

    Local Storage API is never used to cache downloads. Unity does not utilize Local Storage for any purpose.
     
    adamgolden likes this.
  5. DavidWeng

    DavidWeng

    Joined:
    Oct 15, 2022
    Posts:
    7
    Hi, @jukka_j thanks for your response. But what I want to ask is why wasm.unityweb seems to re-download every time the cache goes over 5MB(I've actually measured 5.2MB and it will cache, but 5.4MB cahce will fail), but data.unityweb doesn't? I can easily reproduce this problem in Android's Webview.
     
  6. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    951
    That sounds like a limitation of web browsers that they decide that too large files should not be cached. The "Enable Data Caching" option in Unity is designed to fix that browser issue.
     
  7. DavidWeng

    DavidWeng

    Joined:
    Oct 15, 2022
    Posts:
    7
    Hi, @jukka_j thanks for your response. But I do have Data Caching enabled. data.unityweb is currently cached for sizes over 10MB, but wasm.unityweb is not cached for sizes as small as 5.4MB.
     
  8. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    951
    That is surprising. Any chance you'd have a build hosted somewhere to double check?
     
  9. gilizeeviSG

    gilizeeviSG

    Joined:
    May 12, 2023
    Posts:
    5
  10. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    951
    Data Caching should definitely cache the Wasm file no matter how large it is. I wonder if there is some kind of issue with Android WebView's management of IndexedDB and Cache APIs. If you have a standalone bug case, reporting that would be welcome. If it turns out to be a Chrome issue, we can forward it to the Google bug tracker.

    Unfortunately Wasm splitting is not a turnkey solution that could be adopted for this type of scenario.
     
  11. gilizeeviSG

    gilizeeviSG

    Joined:
    May 12, 2023
    Posts:
    5
    Thanks for the reply. Will work on opening a bug case.
     
    jukka_j likes this.