private static void ClearImpl(object param) { try { string[] cacheEntries = Directory.GetFiles(CacheFolder); for (int i = 0; i < cacheEntries.Length; ++i) { // We need a try-catch block becouse between the Directory.GetFiles call and the File.Delete calls a maintainance job, or other file operations can delelete any file from the cache folder. // So while there might be some problem with any file, we don't want to abort the whole for loop try { string fileName = System.IO.Path.GetFileName(cacheEntries[i]); DeleteEntity(GetUriFromFileName(fileName)); } catch { } } } finally { SaveLibrary(); InClearThread = false; } }
/// <summary> /// Deletes all files from the cache folder that isn't in the Library. /// </summary> private static void DeleteUnusedFiles() { #if !UNITY_WEBPLAYER CheckSetup(); string[] cacheEntries = Directory.GetFiles(CacheFolder); for (int i = 0; i < cacheEntries.Length; ++i) { // We need a try-catch block becouse between the Directory.GetFiles call and the File.Delete calls a maintainance job, or other file operations can delelete any file from the cache folder. // So while there might be some problem with any file, we don't want to abort the whole for loop try { string fileName = System.IO.Path.GetFileName(cacheEntries[i]); Uri uri = GetUriFromFileName(fileName); lock (Library) if (!Library.ContainsKey(uri)) { DeleteEntity(uri); } } catch {} } #endif }
private static void ClearImpl(object param) { if (!IsSupported) { return; } try { // GetFiles will return a string array that contains the files in the folder with the full path string[] cacheEntries = Directory.GetFiles(CacheFolder); for (int i = 0; i < cacheEntries.Length; ++i) { // We need a try-catch block because between the Directory.GetFiles call and the File.Delete calls a maintenance job, or other file operations can delete any file from the cache folder. // So while there might be some problem with any file, we don't want to abort the whole for loop try { File.Delete(cacheEntries[i]); } catch { } } } finally { UsedIndexes.Clear(); library.Clear(); NextNameIDX = 0x0001; SaveLibrary(); InClearThread = false; } }
/// <summary> /// Deletes all cache entity. Non blocking. /// <remarks>Call it only if there no requests currently processed, becouse cache entries can be deleted while a server sends back a 304 result, so there will be no data to read from the cache!</remarks> /// </summary> public static void BeginClear() { #if !UNITY_WEBPLAYER if (InClearThread) { return; } InClearThread = true; SetupCacheFolder(); #if !NETFX_CORE ThreadPool.QueueUserWorkItem(new WaitCallback((param) => #else Windows.System.Threading.ThreadPool.RunAsync((param) => #endif { try { string[] cacheEntries = Directory.GetFiles(CacheFolder); for (int i = 0; i < cacheEntries.Length; ++i) { // We need a try-catch block becouse between the Directory.GetFiles call and the File.Delete calls a maintainance job, or other file operations can delelete any file from the cache folder. // So while there might be some problem with any file, we don't want to abort the whole for loop try { string fileName = System.IO.Path.GetFileName(cacheEntries[i]); DeleteEntity(GetUriFromFileName(fileName)); } catch {} } } finally { SaveLibrary(); InClearThread = false; } } #if !NETFX_CORE ) #endif ); #endif }