private Boolean isCacheValid() { SuggestionCache cache = SuggestionCache; if (cache == null) { return(false); } if ((DateTime.Now - cache.GenerationTime) > new TimeSpan(1, 0, 0)) { return(false); } return(true); }
private void updateCache() { Dictionary <long, long> topDictionary = new Dictionary <long, long>(); IEnumerable <Order> ordersInProgres = OrderInformationsService.GetUndeliveredOrders(); foreach (Order order in ordersInProgres) { foreach (OrderEntry orderEntity in order.OrderEntries) { if (topDictionary.ContainsKey(orderEntity.BookType.Id)) { topDictionary[orderEntity.BookType.Id] += orderEntity.Amount; } else { topDictionary.Add(orderEntity.BookType.Id, orderEntity.Amount); } } } int number = Math.Min(quantity, topDictionary.Count); List <long> topList = new List <long>(); foreach (var pair in topDictionary.OrderBy(i => i.Value).Take(number)) { topList.Add(pair.Key); } if (number < quantity) { fillUpWithRandom(topList); } SuggestionCache newSuggestionCache = new SuggestionCache(); newSuggestionCache.BookList = topList; newSuggestionCache.GenerationTime = DateTime.Now; SuggestionCache = newSuggestionCache; }
private void updateCache() { Dictionary<long, long> topDictionary = new Dictionary<long, long>(); IEnumerable<Order> ordersInProgres = OrderInformationsService.GetUndeliveredOrders(); foreach (Order order in ordersInProgres) { foreach (OrderEntry orderEntity in order.OrderEntries) { if (topDictionary.ContainsKey(orderEntity.BookType.Id)) { topDictionary[orderEntity.BookType.Id] += orderEntity.Amount; } else { topDictionary.Add(orderEntity.BookType.Id, orderEntity.Amount); } } } int number = Math.Min(quantity, topDictionary.Count); List<long> topList = new List<long>(); foreach (var pair in topDictionary.OrderBy(i => i.Value).Take(number)) { topList.Add(pair.Key); } if (number < quantity) fillUpWithRandom(topList); SuggestionCache newSuggestionCache = new SuggestionCache(); newSuggestionCache.BookList = topList; newSuggestionCache.GenerationTime = DateTime.Now; SuggestionCache = newSuggestionCache; }