Search Unity

Cache wont clear at first app start

Discussion in 'Addressables' started by TheFudge, Apr 25, 2019.

  1. TheFudge

    TheFudge

    Joined:
    Apr 28, 2014
    Posts:
    39
    I have a problem with clearing the cache.

    I want to delete every Addressable, if the user desires it.

    For that I call Caching.ClearCache(). I return true, but the data is still there. I tried using Caching.currentCacheForWriting, and it return true, but the data is still there.

    I think maybe some Addressable data is still marked as used or something? Is there a way to unload every Addressable asset, so the Cache Clear will work?

    Code (CSharp):
    1. if (!Caching.ClearCache())
    2.         {
    3.            // Is not called
    4.             Popup.Instance.DisplayMessageRaw("Delete cache failed",
    5.                 "Unfortunately removing the old content did not succeed. Contact the developer for further information. [Cache-10]",
    6.                 () => { });
    7.         }
    8.         if (!Caching.currentCacheForWriting.ClearCache())
    9.         {
    10.            // Is not called
    11.             Popup.Instance.DisplayMessageRaw("Delete cache failed",
    12.                 "Unfortunately removing the old content did not succeed. Contact the developer for further information. [Cache-20]",
    13.                 () => { });
    14.         }
    15.  
    16.        // will say 74.000 bytes, which is the addressable I downloaded.
    17.         Popup.Instance.DisplayMessageRaw("Delete cache succeeded",
    18.             "The current cache is " + Caching.currentCacheForWriting.spaceOccupied.ToString("N0") + " bytes big.",
    19.             () => { });
    Sorry just found that I am getting an Addressable just before the download, so the async operation is doing its thing while I try to delete the cache ;)

    This is addressable is not marked as cachable, so it actually should not block Caching from working correctly.
     
    Last edited: Apr 25, 2019
  2. TheFudge

    TheFudge

    Joined:
    Apr 28, 2014
    Posts:
    39
    New problem:

    I can clear the cache with no problem if when I start the app and not download anything. If I download addressable data and then try to delete it, the Cache returns false.
    I can clear it after I restart the game.

    Is there something I should call so that I can clear the content?
     
    ImpossibleRobert likes this.
  3. ImpossibleRobert

    ImpossibleRobert

    Joined:
    Oct 10, 2013
    Posts:
    529
    Did you ever find a solution to this? Facing it as well.
     
  4. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    @TheFudge if you're getting false it likely means that one of the AssetBundels is currently loaded or being used in some way. Ensure that all of your AsyncOperationHandles that could potentially load a bundle are released prior to trying to clear the cache.

    Other than that if you're getting true returned but data is still in the cache there could be a bug. If that's your case please file a bug so we can look into it.