private static void ClearCache(object obj) { string[] files = Directory.GetFiles(BooksPath(), "*.*", SearchOption.AllDirectories); List <FileComparerInfo> fileList = new List <FileComparerInfo>(files.Length); long size = 0; foreach (string fileName in files) { FileInfo fileInfo = new FileInfo(fileName); FileComparerInfo fileComparerInfo = new FileComparerInfo { DateTime = fileInfo.LastWriteTime, Length = fileInfo.Length, FileInfo = fileInfo }; fileList.Add(fileComparerInfo); size += fileComparerInfo.Length; } fileList.Sort((x, y) => Math.Sign((x.DateTime - y.DateTime).Ticks)); long cacheSize = (long)obj; if (cacheSize != 0) { while ((fileList.Count > 0) && (size > cacheSize)) { size -= fileList[0].Length; fileList[0].FileInfo.Delete(); fileList.RemoveAt(0); } } }
private static void ClearCache(object obj) { string[] files = Directory.GetFiles(BooksPath(), "*.*", SearchOption.AllDirectories); List<FileComparerInfo> fileList = new List<FileComparerInfo>(files.Length); long size = 0; foreach (string fileName in files) { FileInfo fileInfo = new FileInfo(fileName); FileComparerInfo fileComparerInfo = new FileComparerInfo { DateTime = fileInfo.LastWriteTime, Length = fileInfo.Length, FileInfo = fileInfo }; fileList.Add(fileComparerInfo); size += fileComparerInfo.Length; } fileList.Sort((x, y) => Math.Sign((x.DateTime - y.DateTime).Ticks)); long cacheSize = (long) obj; if (cacheSize != 0) { while ((fileList.Count > 0) && (size > cacheSize)) { size -= fileList[0].Length; fileList[0].FileInfo.Delete(); fileList.RemoveAt(0); } } }