Example #1
0
        /// <summary>
        /// 优先从Redis或内存中读取
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="rank"></param>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public static List <ResourceMenuInfo> getResourceMenuFormRedisOrMemory(String userName, int rank, String parentId)
        {
            //暂时先全部执行数据库
            //return getResourceMenu(userName, rank, parentId);

            RedisModel redisModel = getResourceMenuOnlyFormRedisOrMemory(userName);
            //Log4netHelper.WriteErrorLogByLog4Net(typeof(JwtHelp), "查询内存数据:" + JsonConvert.SerializeObject(redisModel));
            List <ResourceMenuInfo> menus = new List <ResourceMenuInfo>();

            if (redisModel == null)
            {//说明redis或内存中没有
                menus = getResourceMenu(userName, rank, parentId);
                setResourceMenuToRedisOrMemory(userName, menus);
                redisModel = new RedisModel()
                {
                    resourceMenuInfoList = menus,
                    updateTime           = WIPCommon.ForamtCurDateTime(),
                    userName             = userName
                };
                //Log4netHelper.WriteInfoLogByLog4Net(typeof(JwtHelp), "redisModel:" + JsonConvert.SerializeObject(redisModel));
            }

            if (redisModel == null)
            {
                return(null);
            }
            return(redisModel.resourceMenuInfoList);

            //*/
        }
Example #2
0
        /// <summary>
        /// 权限写入Redis或内存
        /// </summary>
        /// <param name="menus"></param>
        private static void setResourceMenuToRedisOrMemory(string userName, List <ResourceMenuInfo> menus)
        {
            RedisModel redisModel = new RedisModel()
            {
                userName             = userName,
                resourceMenuInfoList = menus,
                updateTime           = WIPCommon.ForamtCurDateTime()
            };

            if (AuthType == WipAuthType.REDIS)
            {
            }
            else
            {
                //写入缓存中
                wipAuthCacheDict.TryAdd(userName, redisModel); //尝试新增
                wipAuthCacheDict[userName] = redisModel;       //更新
            }
        }