public IEnumerable <T> GetEntities() { var user = Thread.CurrentPrincipal.Identity.Name; var entities = _cache.Get(user); if (entities == null) { Console.WriteLine("No cache value:"); using (var dbContext = new Northwind()) { dbContext.Configuration.LazyLoadingEnabled = false; dbContext.Configuration.ProxyCreationEnabled = false; entities = dbContext.Set <T>().ToList(); } _cache.Set(user, entities, DateTimeOffset.Now.AddDays(1)); } return(entities); }
public int CalculateFibonacci(int index) { if (index == 1 || index == 2) { return(1); } int valueFromCache = cache.Get(index.ToString()); if (valueFromCache != default) { Console.WriteLine("Value from cache: " + valueFromCache); return(valueFromCache); } int calculatedValue = CalculateFibonacci(index - 1) + CalculateFibonacci(index - 2); Console.WriteLine("Calculated value:" + calculatedValue); cache.Set(index.ToString(), calculatedValue, DateTime.Now.AddMinutes(2)); return(calculatedValue); }