Symptoms:
- I want to update or remove an old version of my AssetBundles.
Cause:
You may have problems with your downloaded AssetBundles, or you want to free up space by deleting unused or old AssetBundles.
Resolution:
Solution #1:
Use Caching.ClearCache() to delete all AssetBundles that have been cached by the current application. Caching.ClearCache() returns a bool depending on if it was able to complete the operation or not:
public static void ClearCache () { if (Caching.ClearCache()) { Debug.Log("Successfully cleaned the cache"); } else { Debug.Log("Cache is being used"); } }
If you want to delete a specific AssetBundle version instead of the entire cache, you can use Caching.ClearCachedVersion()
If you want to keep one version and delete all others of a specific AssetBundle, you can use Caching.ClearOtherCachedVersions()
Solution #2:
Use Cache.expirationDelay to set the number of seconds that an AssetBundle may remain unused in the cache before it is automatically deleted. When a bundle is downloaded, the timestamp is stored for that given bundle.
To set the expirationDelay property, an entry for your application needs to be in the Cache folder. That setting is stored in a file in your applications' root Cache folder. If the folder for your application does not exist, the file cannot be written. For that entry to exist, you need to request a bundle. So to set the expirationDelay, first request at least one bundle, which will create the folder for your app's bundles. You could use any bundle to make sure the folder exists before you call that property.
You can use the solutions individually or at the same time.
More Information:
Comments
2 comments
Shouldn't it be Caching.ClearCache() ?
Hello,
We have a game in the market and we have been using WWW.LoadFromCacheOrDownload to download our asset bundles. Now the application data size is growing and we want to control it like the asset bundles not used since X time, should gets automatically deleted, so we tried to set Caching.expirationDelay (for testing we set it to 2 hours but we want it to 7 days in production), but Caching.expirationDelay seems not working at all.
1. It doesn't remove the asset bundle older than Caching.expirationDelay time set by us.
2. When we check the value of Caching.expirationDelay after each app restart, it always stays at "12960000"
We want to clear out old assets (not used since 7 days) and also want to apply the same caching timeout for future assets. Can you suggest whats wrong being done by us!
We are using unity 5.3.4p1
And tested on Android phone and unity ediror.
Article is closed for comments.