예제 #1
0
        /// <summary>
        /// 添加【用户树节点】缓存
        /// </summary>
        public bool SetUserTreeNode(UserTreeNodeCache cacheModel)
        {
            if (GetUserFunc == null)
            {
                throw new FException("您未指定查询用户信息的方法");
            }
            if (cacheModel.UserId <= 0)
            {
                throw new FException("您必须要传入【用户Id】");
            }
            if (cacheModel.ParentId < 0)
            {
                throw new FException("您的推荐人【用户Id】不能为空");
            }
            if (string.IsNullOrWhiteSpace(cacheModel.UserName))
            {
                throw new FException("您必须要传入【用户名】");
            }
            if (cacheModel.ParentId > 0 && string.IsNullOrWhiteSpace(cacheModel.ParentName))
            {
                throw new FException("您必须要传入推荐人【用户名】");
            }

            //把该用户加到他父亲下面的孩子集合
            this.AddToPartOfParentCache(cacheModel.ParentId, cacheModel.UserId);

            //把自己的信息添加到【用户树节点缓存】(如果修改了用户信息,那么需要重置该缓存,以保证数据正确)
            string selfKey = CommonCacheKeys.Build_UserTree_Key(cacheModel.UserId);

            return(this._easyCache.Set(selfKey, cacheModel, _expiresTimeSpan, db: redisdbIndex));
        }
예제 #2
0
        /// <summary>
        /// 移除用户树节点缓存
        /// </summary>
        public void RemoveUserTreeNode(int userId)
        {
            if (GetUserFunc == null)
            {
                throw new FException("您未指定查询用户信息的方法");
            }
            if (userId <= 0)
            {
                return;
            }

            string selfKey = CommonCacheKeys.Build_UserTree_Key(userId);

            this._easyCache.Remove(selfKey, db: redisdbIndex);
        }
예제 #3
0
        /// <summary>
        /// 获取【用户树节点】缓存
        /// </summary>
        public UserTreeNodeCache GetUserTreeNode(int userId)
        {
            if (GetUserFunc == null)
            {
                throw new FException("您未指定查询用户信息的方法");
            }
            if (userId <= 0)
            {
                return(null);
            }

            string key = CommonCacheKeys.Build_UserTree_Key(userId);

            return(this._easyCache.Get(key, () =>
            {
                //读不到缓存从数据库读
                UserTreeNodeCache cacheModel = this.GetUserFormDB(userId);
                return cacheModel;
            }, _expiresTimeSpan, db: redisdbIndex));
        }