public IEnumerable <Category> GetAll()
        {
            Console.WriteLine("Get Categories");
            _categories = _cache.Get(_cacheKey) ?? GetData();

            return(_categories);
        }
Beispiel #2
0
        public IEnumerable <Supplier> GetAll()
        {
            Console.WriteLine("Get Suppliers");

            var user      = Thread.CurrentPrincipal.Identity.Name;
            var suppliers = _cache.Get(user);

            if (suppliers == null)
            {
                Console.WriteLine("Load suppliers from DB");

                using (var dbContext = new Northwind())
                {
                    dbContext.Configuration.LazyLoadingEnabled   = false;
                    dbContext.Configuration.ProxyCreationEnabled = false;
                    suppliers = dbContext.Suppliers.ToList();

                    var policy = new CacheItemPolicy
                    {
                        AbsoluteExpiration = new DateTimeOffset(DateTime.UtcNow.AddSeconds(_expirationInSeconds))
                    };

                    _cache.Set(user, suppliers, policy);
                }
            }

            return(suppliers);
        }