コード例 #1
0
        public static PagingDataSet <User> GetUsers(UserQuery query, bool cacheable)
        {
            PagingDataSet <User> users = null;
            string usersKey            = CacheKeyManager.GetUserQueryKey(query);

            //从缓存读取
            if (HttpContext.Current != null)
            {
                users = HttpContext.Current.Items[usersKey] as PagingDataSet <User>;
            }

            if (users != null)
            {
                return(users);
            }

            if (cacheable)
            {
                users = HHCache.Instance.Get(usersKey) as PagingDataSet <User>;
            }

            if (users == null)
            {
                int         totalRecods;
                List <User> userList = CommonDataProvider.Instance.GetUsers(query, out totalRecods);
                users              = new PagingDataSet <User>();
                users.Records      = userList;
                users.TotalRecords = totalRecods;

                //缓存
                if (cacheable)
                {
                    HHCache.Instance.Insert(usersKey, users, 1);
                    AddCachedUser(userList);
                }
                if (HttpContext.Current != null)
                {
                    HttpContext.Current.Items[usersKey] = users;
                }
            }
            return(users);
        }