Search Unity

Cache busting solution for StreamingAssets folder

Discussion in 'Web' started by SleepyAgapornis, Jan 29, 2021.

  1. SleepyAgapornis

    SleepyAgapornis

    Joined:
    Sep 7, 2018
    Posts:
    23
    Hello. I'm currently working on a WebGL game that constantly updates. The problem is that we get reports of errors coming from users playing old versions of the files within the streamingassets folder.
    Is there a good way to cache bust this folder? I found no way of procedurally rename it by adding an Application version suffix or something similar.
     
    Last edited: Jan 29, 2021
  2. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    just an idea...
    does this happen with a folder other than this one?
    what if you use a own folder and get the files with Application.absoluteURL ?

    Code (CSharp):
    1. string url = Application.absoluteURL;
    2. int index = url.LastIndexOf("/");
    3. if (inde > 0) url.Substring(0, index + 1);
    4.  
    5. //the StreamingAssets folder would be:
    6. string streamingAssetsFolder = url + "StreamingAssets/";
    7.  
    8. //but you can use any folder here:
    9. string myOwnAssetsFolder = url + "MyOwnFolder/";
     
  3. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    If you are seeing stale files after an update, there may be a couple of causes.

    First that comes to mind is that the web server that is used to host, is serving the files with caching HTTP response header directives that are telling the browser to keep using the old file. See HTTP Cache-Control documentation on how to control this: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control .

    Use the browser DevTools Network tab to debug and diagnose what kind of caching the remote server is advertising for the files.

    Second is that if the game is hosted on a larger CDN that has geodistributed/load-balanced proxy fronts, then it is possible that those proxies are caching the files. Invalidating such caching depends on the CDN in question.

    Third, check whether the Unity project "Data Caching" option has an effect here. While the Data Caching option should be honoring ETags and Last-Modified dates, it is good to verify that.

    Fourth, if your server is not using ETags as Cache Control, consider whether they can help as an improved caching mechanism over Last-Modified timestamps. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
     
    SleepyAgapornis likes this.
  4. SleepyAgapornis

    SleepyAgapornis

    Joined:
    Sep 7, 2018
    Posts:
    23
    thanks for your answer! currently, I´m able to cache bust almost everything except the files catalog.json and settings.json which are part of the addressable system... I´ve tried everything but I keep getting error reports of unity loading invalid addressable keys after updates :(