示例#1
0
        public IEnumerable <Employee> Select()
        {
            key = Thread.CurrentPrincipal.Identity.Name;
            Thread.Sleep(2000);
            var result = redisCache.GetFromRedis <Employee>(key);

            if (result == null)
            {
                var item = LoadData();
                redisCache.AddToRedis(key, item);
                return(item);
            }
            return(result);
        }
示例#2
0
        private IEnumerable <T> GetDataForRedisCache <T>() where T : class
        {
            var key    = Thread.CurrentPrincipal.Identity.Name;
            var result = redisCache.GetFromRedis <T>(key);

            if (result == null)
            {
                Console.WriteLine("From DB");
                result = GetDataFromDB <T>();
                redisCache.AddToRedis(key, result);
            }
            else
            {
                Console.WriteLine("From cache");
            }

            return(result);
        }