/// <summary> /// Gets all the keys that are saved in the cache /// </summary> /// <returns>The IEnumerable of keys</returns> public IEnumerable <string> GetKeys(CacheState state = CacheState.Active) { IEnumerable <Banana> allBananas; lock (dblock) { allBananas = db.Query <Banana>($"SELECT Id FROM {nameof(Banana)}"); } if (allBananas != null) { var bananas = new List <Banana>(); if (state.HasFlag(CacheState.Active)) { bananas = allBananas .Where(x => GetExpiration(x.Id) >= DateTime.UtcNow) .ToList(); } if (state.HasFlag(CacheState.Expired)) { bananas.AddRange(allBananas.Where(x => GetExpiration(x.Id) < DateTime.UtcNow)); } return(bananas.Select(x => x.Id)); } return(new string[0]); }
public IEnumerable <string> ReadKeys(CacheState state = CacheState.Active) { try { IEnumerable <Yarn> allYarns = _column.FindAll(); if (allYarns != null) { IEnumerable <Yarn> yarns = new List <Yarn>(); if (state.HasFlag(CacheState.Active)) { yarns = allYarns.Where(x => ReadExpirationTime(x.Id) >= DateTime.UtcNow); } else if (state.HasFlag(CacheState.Expired)) { yarns = allYarns.Where(x => ReadExpirationTime(x.Id) < DateTime.UtcNow); } return(yarns.Select(x => x.Id)); } } catch (Exception exc) { exc.WriteFormattedMessageToDebugConsole(typeof(Cotton)); } return(default(IEnumerable <string>)); }
/// <summary> /// Gets all the keys that are saved in the cache /// </summary> /// <returns>The IEnumerable of keys</returns> public IEnumerable <string> GetKeys(CacheState state = CacheState.Active) { var allBananas = col.FindAll(); if (allBananas != null) { var bananas = new List <Banana>(); if (state.HasFlag(CacheState.Active)) { bananas = allBananas .Where(x => GetExpiration(x.Id) >= DateTime.UtcNow) .ToList(); } if (state.HasFlag(CacheState.Expired)) { bananas.AddRange(allBananas.Where(x => GetExpiration(x.Id) < DateTime.UtcNow)); } return(bananas.Select(x => x.Id)); } return(new string[0]); }
/// <summary> /// Gets all the keys that are saved in the cache /// </summary> /// <returns>The IEnumerable of keys</returns> public IEnumerable <string> GetKeys(CacheState state = CacheState.Active) { indexLocker.EnterReadLock(); try { if (index != null) { var bananas = new List <KeyValuePair <string, Tuple <string, DateTime> > >(); if (state.HasFlag(CacheState.Active)) { bananas = index .Where(x => x.Value.Item2 >= DateTime.UtcNow) .ToList(); } if (state.HasFlag(CacheState.Expired)) { bananas.AddRange(index.Where(x => x.Value.Item2 < DateTime.UtcNow)); } return(bananas.Select(x => x.Key)); } return(new string[0]); } catch (Exception) { return(new string[0]); } finally { indexLocker.ExitReadLock(); } }