- Home /
how to delete specific files from cache?
Hello
We use WWW.LoadFromCacheOrDownload() to download and cache assetbundles in our (android/ios) project. We would like to delete some specific (not all) old cached files.
When the user switches in game quality, we re-download some asset files, and would like to remove some of the old ones. So we would not want to re download everything again, just some specific files.
We use a webservice to download files, which generates the same urls for low/medium/high quality files. So we can't just re download the file with the same url, because it's the same version, so unity won't download them again.
Is there a way to delete specific cached files?
Answer by ricardo_arango · Jul 22, 2013 at 10:02 PM
In Unity 4.2 it is now possible to pass a CRC check for the file when you use LoadFromCacheOrDownload. If the CRC passed is different from what is calculated from the file in cache, the file will be considered to be in an invalid state and it will be deleted from the Cache. This is a trick you can use to delete specific files from the Cache:
http://docs.unity3d.com/Documentation/ScriptReference/WWW.LoadFromCacheOrDownload.html
The CRC for an AssetBundle is currently printed on the Editor log file after the AssetBundle is built. In an upcoming Unity 4.x version this value will be returned by the BuildAssetBundle function.
Answer by originalNarf · Jan 23, 2013 at 11:52 PM
I'm looking (and failing to find) the same thing you are, but! LoadFromCacheOrDownload() provides a version number for this kind of problem. What you could do, I think, is increment the version number every time you change resolution, which according to the docs would force a new download every time.
Answer by avianling · Nov 01, 2015 at 10:57 PM
Deleting a file from the cache is covered here: http://answers.unity3d.com/questions/23095/what-is-the-return-value-of-cachingdeletefromcache.html
The function described in this article is depreciated and does nothing.
Your answer
Follow this Question
Related Questions
Clean Cache on Mobile 0 Answers
Asset Bundles with In-App Payment in Unity Mobile 1 Answer
Android multiple WWW freezes 0 Answers