public ActionResult Add(tb_config_model model) { using (DbConn conn = DbConfig.CreateConn(DataConfig.MqManage)) { conn.Open(); bool flag = configDal.Add(conn, model); if (flag) { CacheManage.Remove("configCache"); return(RedirectToAction("index")); } else { ModelState.AddModelError("Error", "更新错误"); return(View(model)); } } }
/// <summary> /// 设置全局一级缓存 /// </summary> /// <param name="key">缓存键</param> /// <param name="value">缓存值</param> /// <param name="minute">缓存时间(单位分钟,可使用小数,默认30分钟)</param> /// <returns></returns> public static bool CacheSet(string key, object value, double minute = 30) { if (value == null) { return(false); } try { CacheManage cache = CacheManage.LocalInstance; cache.Set(key, value, minute); return(true); } catch (Exception ex) { Log.WriteLogToTxt(string.Format("更新缓存信息[CacheSet]:{0}", ex.Message)); return(false); } }
/// <summary> /// 新增手机用户缓存数据 有个更新 没有就新增 /// </summary> /// <param name="KeyNum">键</param> /// <param name="Info">值</param> /// <param name="CacheMinute">缓存时间</param> /// <returns></returns> public static bool SetAppCache(string KeyNum, object Info, double CacheMinute = 15) { if (Info == null || string.IsNullOrEmpty(KeyNum)) { return(false); } try { var _KeyNum = $"AppCache:{KeyNum}"; CacheManage cache = CacheManage.LocalInstance; cache.Set(_KeyNum, Info, CacheMinute); return(true); } catch (Exception ex) { Log.WriteLogToTxt(string.Format("新增手机用户缓存数据[SetAppCache]:{0}", ex.Message)); return(false); } }
/// <summary> /// 新增用户缓存数据 有个更新 没有就新增 /// </summary> /// <param name="KeyNum">键</param> /// <param name="Info">值</param> /// <returns></returns> public static bool UpdateCache(string KeyNum, object Info) { if (Info == null) { return(false); } try { var _KeyNum = string.Concat(KeyNum, GetIdentityKey); CacheManage cache = CacheManage.LocalInstance; cache.Add(_KeyNum, Info, 15); return(true); } catch (Exception ex) { Log.WriteLogToTxt(string.Format("更新用户缓存信息[UpdateUserInfoCache]:{0}", ex.Message)); return(false); } }
static void CheckNet() { try { if (cacheManage == null) { cacheManage = new CacheManage(); } if (configManage == null) { configManage = new ConfigManage( m_ServerIp, //ConfigurationManager.AppSettings["REMOTEIP"].ToString(), int.Parse(ConfigurationManager.AppSettings["RemoteSKPORT"].ToString()), int.Parse(ConfigurationManager.AppSettings["RemoteRMPORT"].ToString())); //连接服务器套接字、REMOTING configManage.OnError += new ConfigManage.Error(_configManage_OnError); //错误处理 } } catch { Thread.Sleep(1); } }
public static bool RemoveCache(string KeyNum, string IdentityKey) { try { var _KeyNum = string.Concat(KeyNum, IdentityKey); CacheManage cache = CacheManage.LocalInstance; cache.Remove(_KeyNum); if (KeyNum.Equals("USERINFO:")) { cache.Remove(string.Concat("USERINFO-TuthorityManager", IdentityKey)); cache.Remove(string.Concat("GetTimes:", IdentityKey)); } return(true); } catch (Exception ex) { Log.WriteLogToTxt(string.Format("移除缓存数据[RemoveUserInfoCache]:{0}", ex.Message)); return(false); } }
static void Main(string[] args) { //说明:如果你确定缓存一定是在本机,使用:CacheManage cache= CacheManage.LocalInstance //如果只是缓存一般数据,将来有可能启用分布式时,用:CacheManage cache = CacheManage.Instance; //比如框架对一些表架构的元数据的缓存,用的是本机(速度快):CacheManage.LocalInstance //而框架对于自动缓存(表的数据),用的是:CacheManage.Instance (将来随便分布式启用分散到各缓存服务器) AppConfig.Cache.MemCacheServers = "127.0.0.1:11211";//配置启用MemCache,127.0.0.1:11212 CacheManage cache = CacheManage.Instance; if (!cache.Contains("a1")) { cache.Set("a1", "a1", 0.1); } cache.Set("a2", "a2", 0.5);//存在则更新,不存在则添加。 cache.Set("a3", "a3", 2.2); cache.Set("a0", "a0"); cache.Set("table", cache.CacheInfo); Console.WriteLine(cache.Get <string>("a0")); Console.WriteLine(cache.Get <string>("a1")); Console.WriteLine(cache.Get <string>("a2")); Console.WriteLine(cache.Get <string>("a3")); MDataTable table = cache.Get <MDataTable>("table"); if (table != null) { Console.WriteLine(table.Rows.Count); } if (cache.CacheType == CacheType.LocalCache)//只能拿到本机的信息 { Console.WriteLine("缓存数:" + table.Rows.Count); Console.WriteLine("总内存(M):" + GC.GetTotalMemory(false) / 1024); // 感觉拿到的值不太靠谱。 } cache.Remove("a0"); //单个移除 cache.Clear(); //清除所有缓存 Console.Read(); }
/// <summary> /// 获取沙龙昵称和logo /// </summary> /// <param name="suid"></param> /// <returns></returns> private string cacheInfo(string suid) { string info = ""; try { info = CacheManage.GetCache("suid:" + suid).ToString(); } catch { List <AllSalon> list = new List <AllSalon>(); SalonService sa = new SalonService(); //取沙龙的基本信息和环境图 list = sa.GetSalonInfo(new Guid(suid), 3); if (list.Any()) { info = list[0].Nickname + "|*-*|" + list[0].Logo; CacheManage.SetCacheMinutes("suid:" + suid, info, 90); } } return(info); }
/// <summary> /// 数据结构行刷新 /// </summary> /// <param name="objName"></param> /// <param name="objCode"></param> /// <param name="dt">原有数据</param> /// <returns></returns> public static bool Flesh(string objName, string objCode, MDataTable dt, out string msg) { bool result = false; msg = LangConst.NoNewColumn; MDataTable newDt = dt.GetSchema(false); //移除表结构缓存 string tableKey = CacheManage.GetKey(CacheKeyType.Schema, objName, CrossDb.GetConn(objName)); CacheManage.LocalInstance.Remove(tableKey); FillTable(objName, objCode, newDt);//重新获取。 MDataTable addTable = dt.GetSchema(false); // bool needUpdate = false; foreach (MDataRow row in newDt.Rows) { MDataRow mr = dt.FindRow(string.Format("Field='{0}'", row.Get <string>("Field"))); if (mr == null)//找不到,则添加行 { row.Set(Config_Grid.OrderNum, 255); row.Set(Config_Grid.Hidden, true); row.Set(Config_Grid.GridID, Guid.NewGuid()); addTable.Rows.Add(row); } } if (addTable.Rows.Count > 0) { result = addTable.AcceptChanges(AcceptOp.InsertWithID); if (!result) { msg = Convert.ToString((Exception)addTable.DynamicData); } } return(result); }
/// <summary> /// 根据操作标识和用户标识检测是否没超过限制次数 /// 默认1440分钟,1次,使用URL和GetIdentityKey作为Key /// 如:CommonContext.VisitCheck(1, 1440, "HitIndustry" + id, userId); /// </summary> /// <param name="minute">限制分钟数,默认1440分钟(24小时)</param> /// <param name="limit">限制次数,默认1</param> /// <param name="mark">操作标识,默认URL,可指定为:需求名+Id、产品名+Id、设计师名+Id等</param> /// <param name="userKey">用户标识,默认GetIdentityKey,可指定为:用户名或用户ID等</param> /// <returns></returns> public static bool VisitCheck(double minute = 1440, int limit = 1, object mark = null, object userKey = null) { if (limit > 0 && minute > 0) { mark = mark ?? HttpContext.Current.Request.Url; userKey = userKey ?? GetIdentityKey; string key = "VisitCheck:" + MD5Encrupt($"{userKey}{mark}"); CacheManage cache = CacheManage.LocalInstance; var value = cache.Get(key); if (value != null)//已经访问过 { try { int times = (int)value; if (times < limit) //未超过限制次数 { cache.Set(key, times + 1, minute); return(true); } else //超过次数 { return(false); } } catch (Exception) { return(true); } } else //未访问过 { cache.Set(key, 1, minute); } } return(true); }
///// <summary> ///// 加载Html后是否清除所有注释节点。 ///// </summary> //private bool clearCommentOnLoad = false; public XHtmlBase() { //License.Check(DAL.DalCreate.XHtmlClient); _XmlDocument = new XmlDocument(); theCache = CacheManage.LocalInstance; }
public DataCache(CacheManage cacheMgr) : base(cacheMgr) { }
public ABAssetInfo(string sPath, CacheManage mgr) : base(sPath, mgr) { Path = sPath; }
///// <summary> ///// ����Html���Ƿ��������ע�ͽڵ㡣 ///// </summary> //private bool clearCommentOnLoad = false; public XHtmlBase() { //License.Check(DAL.DalCreate.XHtmlClient); _XmlDocument = new XmlDocument(); theCache = CacheManage.LocalInstance; }
public AssetInfo(string sPath, CacheManage mgr) : base(mgr) { Path = sPath.ToLower(); }
public Cache(CacheManage mgr) { m_Mgr = mgr; }