Documentation

Unity Engine

Download Unity

Unity Engine

ClearCache

Deletes all the AssetBundles stored in every cache in the cache list.
Read time 2 minutesLast updated 12 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

ClearCache()

Deletes all the AssetBundles stored in every cache in the cache list.
public static bool ClearCache()

Returns

Type

Description

boolTrue if every cache was cleared. False if a cache couldn't be cleared, for example because one of its AssetBundles is loaded.

Remarks

This method calls Cache.ClearCache on each cache in the cache list, in order, and stops at the first cache that can't be cleared. Caches earlier in the list are already cleared at that point. Unload all AssetBundles that were loaded from the cache before you call this method.
Additional Resources: AssetBundle caching.

Examples

using System.IO;using UnityEngine;public class Example : MonoBehaviour{ void ClearCacheExample() { Directory.CreateDirectory("Cache1"); Directory.CreateDirectory("Cache2"); Directory.CreateDirectory("Cache3"); Caching.AddCache("Cache1"); //Placed in cache list at position 1 Caching.AddCache("Cache2"); //Placed in cache list at position 2 Caching.AddCache("Cache3"); //Placed in cache list at position 3 //Clears all of the caches bool success = Caching.ClearCache(); if (!success) { Debug.Log("Unable to clear cache"); } }}

ClearCache(int)

Deletes the AssetBundle versions in every cache in the cache list that haven't been used for longer than the specified number of seconds.
public static bool ClearCache(int expiration)

Parameters

expiration

Number of seconds since a version was last used, after which this method deletes it.

Returns

Type

Description

boolAlways true.

Remarks

This method calls Cache.ClearCache with
expiration
on each cache in the cache list. It skips versions that are currently loaded.
When a cache is opened, at application startup or when you call Caching.AddCache, Unity deletes the versions in it that haven't been used for 150 days. Use this method to delete unused versions sooner.
Additional Resources: AssetBundle caching.