/// <summary> /// If any file timestamp is in the future /// (beyond now + FUTURE_TIMESTAMP_THRESHOLD_MS), we will set its /// effective timestamp to 0 (the beginning of unix time), thus /// sending it to the head of the queue for eviction (entries with /// the lowest timestamps are evicted first). This is a safety check /// in case we get files that are written with a future timestamp. /// We are adding a small delta (this constant) to account for /// network time changes, timezone changes, etc. /// </summary> private ICollection <IEntry> GetSortedEntries(ICollection <IEntry> allEntries) { DateTime threshold = _clock.Now.AddMilliseconds(FUTURE_TIMESTAMP_THRESHOLD_MS); List <IEntry> sortedList = new List <IEntry>(allEntries.Count); List <IEntry> listToSort = new List <IEntry>(allEntries.Count); foreach (var entry in allEntries) { if (entry.Timestamp > threshold) { sortedList.Add(entry); } else { listToSort.Add(entry); } } listToSort.Sort(_entryEvictionComparatorSupplier.Get()); sortedList.AddRange(listToSort); return(sortedList); }