예제 #1
0
        public static LoginInfo LoginInfo(string ID)
        {
            string key = LoginCacheName + ID;

            //if (!System.Web.HttpContext.Current.Request.Headers.AllKeys.Contains(key))
            //{
            //    if (!CacheExtensions.CheckCache(key))
            //    {
            //        var employee = MvcCore.Unity.Get<IEmployeeService>().Single(ID);
            //        if (employee == null || employee.IsDisabled.GetValueOrDefault(false))
            //        {
            //            Logout();
            //            throw new UnauthorizedAccessException("用户信息失效!");
            //        }
            //        employee.ToLoginInfo().SetCache();
            //    }
            //    System.Web.HttpContext.Current.Request.Headers.Set(key, CacheExtensions.GetCache<LoginInfo>(key).ToJson());
            //}
            //return HttpContext.Current.Request.Headers.Get(key).FromJson<LoginInfo>();

            if (!CacheExtensions.CheckCache(key))
            {
                var employee = MvcBase.Unity.Get <IEmployeeService>().Single(ID);
                if (employee == null || employee.IsDisabled.GetValueOrDefault(false))
                {
                    Logout();
                    return(null);
                }
                employee.ToLoginInfo().SetCache();
            }
            return(CacheExtensions.GetCache <LoginInfo>(key));
        }
예제 #2
0
 public virtual List <T> ListCache(string cacheName, CacheTimeType cacheTimeType, int cacheTime, Expression <Func <T, bool> > where, int count)
 {
     if (!CacheExtensions.CheckCache(cacheName))
     {
         CacheExtensions.SetCache(cacheName, (object)this.dbset.AsNoTracking <T>().Where <T>(where).Take <T>(count).ToList <T>(), cacheTimeType, cacheTime);
     }
     return(CacheExtensions.GetCache <List <T> >(cacheName));
 }
예제 #3
0
 public virtual List <T> ListCache(string cacheName, CacheTimeType cacheTimeType, int cacheTime)
 {
     if (!CacheExtensions.CheckCache(cacheName))
     {
         CacheExtensions.SetCache(cacheName, (object)this.dbset.AsNoTracking <T>().ToList <T>(), cacheTimeType, cacheTime);
     }
     return(CacheExtensions.GetCache <List <T> >(cacheName));
 }
예제 #4
0
        public static List <LoginInfo> LoginInfo()
        {
            List <LoginInfo> result = new List <LoginInfo>();

            foreach (var key in CacheExtensions.GetAllCache().Where(s => s.StartsWith(LoginCacheName)))
            {
                result.Add(CacheExtensions.GetCache <LoginInfo>(key));
            }
            return(result);
        }