Search Unity

Caching.ClearOtherCachedVersions is super aggressive

Discussion in 'Asset Bundles' started by HarryCodder, Sep 20, 2017.

  1. HarryCodder


    Feb 20, 2015
    Hello all,

    I just tested the new Caching functions in 2017.1 a few days ago and I discovered that Caching.ClearOtherCachedVersions is (probably overly) aggressive.

    I believe this method purpose is to remove older cached versions of a bundle but it's currently not usable like that at all.

    From what I could test, it seems bundles are cached in a folder which name is only the filename of the bundle without its variant.

    To me, this creates two problematic scenarios:
    1. Bundles named "somebundle" and "somefolder/somebundle" are cached in the same directory
    2. Bundles with variants ("somebundle.variant1", "somebundle.variant2", etc...) are also cached in the same directory.
    From my tests, I believe Caching.ClearOtherCachedVersions just list all bundles in the corresponding directory and deletes the ones which hash is not the one provided to the function.

    This means that while trying to remove an older cached version of "somebundle", you would also delete all other variants and all versions of "somefolder/somebundle".

    For the first case, I'm pretty sure it's a bug and not the intended behaviour.
    For the second case, I guess you could say it's as designed if you believe variants are to be mutually exclusive but it's not always the case (language variants for exemple, you might want to cache them all to switch at runtime).

    Anyway, if someone can provide some feedback about that, it would be nice.
    For the time being, I just redid the method myself by manually removing files and directories from the caching folder which path we can retrieve now (yay).
    Last edited: Sep 21, 2017
    guneyozsan likes this.
  2. HarryCodder


    Feb 20, 2015
    Hello everyone,

    I just stumbled upon the documentation for UnityWebRequest.GetAssetBundle which explains how the cache works and the new option to override the bundle name in the cache which can solve part of this problem.

    The part that it cannot solve is the one about variants because it you specify "somebundle.variant" as a bundle name in the cache, the folder just remove the extension.
    OgoneTech and guneyozsan like this.