public static void ClearCache(bool WinINet = false) { FileInfo[] CacheFiles = CacheDirectory.GetFiles(); foreach (FileInfo CacheFile in CacheFiles) { try { CacheFile.Delete(); } catch { continue; } } DirectoryInfo[] CacheDirectories = CacheDirectory.GetDirectories(); foreach (DirectoryInfo CacheFolder in CacheDirectories) { try { CacheFolder.Delete(true); } catch { continue; } } if (WinINet) { try { (Process.Start("RunDll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 10")).Dispose(); } catch { } } }
public static void ClearPrintCache(string CacheFolder) { DirectoryInfo CacheDir = new DirectoryInfo(CacheFolder); if (CacheDir.Exists) { DateTime DeleteTime = DateTime.UtcNow - TimeSpan.FromDays(5.0); foreach (FileInfo CacheFile in CacheDir.EnumerateFiles()) { if (CacheFile.LastWriteTimeUtc < DeleteTime || CacheFile.Name.EndsWith(".temp", StringComparison.OrdinalIgnoreCase)) { try { CacheFile.Attributes = FileAttributes.Normal; CacheFile.Delete(); } catch { } } } } }