Search Unity

[1.5] Overwriting old cached assets

Discussion in 'Addressables' started by carlbinalla, Jan 27, 2020.

  1. carlbinalla

    carlbinalla

    Joined:
    Mar 5, 2018
    Posts:
    7
    With
    ClearDependencyCacheAsync()
    , I can remove a cached asset, much like
    Caching.Clear()
    but for a specific key. The problem is that, whenever that specific key detected an update from the server using
    GetDownloadSizeAsync()
    , when I now use
    ClearDependencyCacheAsync()
    , it is not removing the cached asset.

    This is more or less the code:

    Code (CSharp):
    1. void Start()
    2. {
    3.     Addressables.GetDownloadSizeAsync(key).Completed += SizeDone;
    4. }
    5.  
    6. void SizeDone(AsyncOperationHandle<long> obj)
    7. {
    8.     long fileSize = obj.Result;
    9.         if (fileSize == 0)
    10.         {
    11.             //Asset is cached
    12.             //
    13.             //
    14.         }
    15.         else
    16.         {
    17.             //Since it is a new asset, it will come here
    18.             Addressables.LoadSceneAsync(key, LoadSceneMode.Single, false).Completed += SceneDone;
    19.         }
    20.  
    21.         Addressables.Release(obj);
    22. }
    After these, the asset/scene is now cached. Now, when I do this:

    Code (CSharp):
    1. void Start()
    2. {
    3.     Addressables.ClearDependencyCacheAsync(key);
    4. }
    As expected, the cached asset is removed, as proven by the reduction of the file size. But if you cached again the asset, then do an update to the asset and run this code:

    Code (CSharp):
    1. void Start()
    2. {
    3.     Addressables.GetDownloadSizeAsync(key).Completed += SizeDone;
    4. }
    5.  
    6. void SizeDone(AsyncOperationHandle<long> obj)
    7. {
    8.     long fileSize = obj.Result;
    9.         if (fileSize == 0)
    10.         {
    11.             //Asset is cached
    12.             //
    13.             //
    14.         }
    15.         else
    16.         {
    17.             //It will enter here, as there is an update, so we need to clear first the old asset and download the new one
    18.             Addressables.ClearDependencyCacheAsync(key);
    19.             Addressables.LoadSceneAsync(key, LoadSceneMode.Single, false).Completed += SceneDone;
    20.         }
    21.  
    22.         Addressables.Release(obj);
    23. }
    The old asset was not cleared, and the new asset just added to the file size. I was expecting that the old asset will be removed first, then download the new one. I also tried using the handle as the argument, but it has the same result.

    Is this the right way? or are there other syntax that is used for cleaning old assets. Since there is no outright way of overwriting an old asset, I tried doing this. Unfortunately, it didn't work
     
  2. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    ClearDependencyCacheAsync API doesn't even make sense. It doesn't return anything that can be awaited, and doesn't accept any callbacks as arguments.