/// <summary> /// 无则插入,有则更新缓存 /// </summary> public static void AddUser(string key, M_UserInfo mu) { if (UserSession.ContainsKey(key)) { M_Cache model = (M_Cache)UserSession[key]; model.LastUpdateTime = DateTime.Now; model.model = mu; } else { M_Cache model = new M_Cache(mu); UserSession.Add(key, model); } }
//最终用于清除的方法,过期与主动都调用其 public static void ClearByKeys(string keys) { keys = keys.TrimEnd(','); if (!string.IsNullOrEmpty(keys)) { try { foreach (string key in keys.Split(',')) { //后期改为缓存事件分发 M_Cache model = UserSession[key]; B_User.UpdateField("LastActiveTime", (DateTime.Now.AddMinutes(-ActiveSpan)).ToString(), model.UserID, false); UserSession.Remove(key); } } catch (Exception ex) { ZLLog.L(Model.ZLEnum.Log.labelex, "用户缓存出错:" + ex.Message); } } }