/// <summary> /// Removing oldest cache file (file, which last access time is smaller) /// </summary> private bool RemoveOldestCacheFile() { if (_lastAccessTimeDictionary.Count == 0) { return(false); } var oldestCacheFilePath = _lastAccessTimeDictionary.Aggregate((pair1, pair2) => (pair1.Value < pair2.Value)? pair1 : pair2).Key; if (String.IsNullOrEmpty(oldestCacheFilePath)) { return(false); } try { long fileSizeInBytes; using (var file = ISF.OpenFile(oldestCacheFilePath, FileMode.Open, FileAccess.Read)) { fileSizeInBytes = file.Length; } try { ISF.DeleteFile(oldestCacheFilePath); _lastAccessTimeDictionary.Remove(oldestCacheFilePath); CurrentCacheSizeInBytes -= fileSizeInBytes; // Updating current cache size JetImageLoader.Log("[delete] cache file " + oldestCacheFilePath); return(true); } catch { JetImageLoader.Log("[error] can not delete oldest cache file: " + oldestCacheFilePath); } } catch { JetImageLoader.Log("[error] can not get olders cache's file size: " + oldestCacheFilePath); } return(false); }