public IEnumerable<Product> GetProducts() { var user = Thread.CurrentPrincipal.Identity.Name; var products = cache.Get(user); if (products == null) { Console.WriteLine("From DB"); using (var dbContext = new Northwind()) { dbContext.Configuration.LazyLoadingEnabled = false; dbContext.Configuration.ProxyCreationEnabled = false; products = dbContext.Products.ToList(); cache.Set(user, products); } } return products; }
public IEnumerable<Category> GetCategories() { Console.WriteLine("Get Categories"); var user = Thread.CurrentPrincipal.Identity.Name; var categories = cache.Get(user); if (categories == null) { Console.WriteLine("From DB"); using (var dbContext = new Northwind()) { dbContext.Configuration.LazyLoadingEnabled = false; dbContext.Configuration.ProxyCreationEnabled = false; categories = dbContext.Categories.ToList(); cache.Set(user, categories); } } return categories; }