Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Solved] Caching control

Discussion in 'Addressables' started by locus84, Dec 20, 2019.

  1. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    Hi guys.

    I have a question about cache control.

    For my previous projects.
    When I start the game, I download needed assetbundles and Cache.MarkAsUsed for already cached assetbudles.
    And then, I simply call Caching.CleanCahe((int)Time.realtimeSinceStartup + Threshold).
    This way, I was able to clean up all bundles that is currently not using.

    So I want to implement similar functionality with Addressables too.
    I found bundles from ResourceLocator keys (which ends with ".bundle")
    But I can't call Cache.MarkAsUsed as it says it's always not cached.

    //foreach(var bundleName in bundleNames)
    //{
    // var fileName = System.IO.Path.GetFileNameWithoutExtension(bundleName);
    // var splited = fileName.Split('_');
    // var hashString = splited[splited.Length - 1];
    // var actualName = fileName.Remove(fileName.Length - (hashString.Length + 1), hashString.Length + 1);
    // var bundle = new CachedAssetBundle(actualName, Hash128.Compute(hashString));
    // Debug.Log($"Filename : {actualName} is {Caching.IsVersionCached(bundle)}");
    //}

    I want to know which name Addressable uses as an actual bundle name.
    So I can create CachedAssetBundle to MarkAsUsed.

    PS. I see ClearDependencyCacheAsync function in addressables,
    How's adding MarkDependencyCacheUsedAsync??

    Thank you!
     
    dirty-rectangle likes this.
  2. locus84

    locus84

    Joined:
    Mar 30, 2011
    Posts:
    119
    My bad, I was using Hash.Compute instead of Hash.Parse.
    Marked title as solved.