Exemple #1
0
 /// <summary>
 /// 将用户缓存信息写入缓存(异步)
 /// </summary>
 /// <param name="userId">目标用户编号</param>
 /// <param name="userCache">缓存数据</param>
 public static async void SetUserCacheInfo(int userId, UserCacheInfo userCache = null)
 {
     await Task.Run(() =>
     {
         UserCacheInfo cacheInfo = userCache == null ? ReadUserCacheInfoFromDb(userId) : userCache;
         if (null != cacheInfo)
         {
             new UserCacheData {
                 UserId = cacheInfo.UserId, CacheData = cacheInfo.ProtoBufSerialize <UserCacheInfo>()
             }
         }
         .UserCacheStorage();
     });
Exemple #2
0
        /// <summary>
        /// 从缓存中读取用户缓存信息
        /// </summary>
        /// <param name="userId">目标用户编号</param>
        /// <returns>用户缓存信息</returns>
        public static UserCacheInfo ReadUserCacheInfo(int userId)
        {
            UserCacheData cacheData = userId.GetUserCacheFromStorage();

            if (null != cacheData && null != cacheData.CacheData && cacheData.CacheData.Length > 0)
            {
                return(cacheData.CacheData.ProtoBufDeserialize <UserCacheInfo>());
            }

            UserCacheInfo cacheInfo = ReadUserCacheInfoFromDb(userId);

            if (null == cacheInfo)
            {
                return(cacheInfo);
            }

            cacheData = new UserCacheData {
                UserId = cacheInfo.UserId, CacheData = cacheInfo.ProtoBufSerialize <UserCacheInfo>()
            };
            cacheData.UserCacheStorage();
            return(cacheInfo);
        }