private string GetJson(MDataColumn mdc) { JsonHelper js = new JsonHelper(); foreach (var cell in mdc) { js.Add("Key", cell.ColumnName); js.Add("Value", cell.ColumnName); js.AddBr(); } return js.ToString(true); }
//End internal static void SetCache(AopEnum action, AopInfo aopInfo) { string baseKey = GetBaseKey(aopInfo); switch (action) { case AopEnum.ExeNonQuery: case AopEnum.Insert: case AopEnum.Update: case AopEnum.Delete: if (aopInfo.IsSuccess || aopInfo.RowCount > 0) { ReadyForRemove(baseKey); } return; } //if (!IsCanOperateCache(baseKey)) //{ // return; //} if (_MemCache.CacheType == CacheType.LocalCache && _MemCache.RemainMemoryPercentage < 15)//可用内存低于15% { return; } string key = GetKey(action, aopInfo, baseKey); int flag;//0 正常;1:未识别;2:不允许缓存 SetBaseKeys(aopInfo, key, out flag);//存档Key,后续缓存失效 批量删除 if (flag == 2) { return;// } double cacheTime = Math.Abs(12 - DateTime.Now.Hour) * 60 + DateTime.Now.Second;//缓存中午或到夜里1点 if (flag == 1 || aopInfo.PageIndex > 2) // 后面的页数,缓存时间可以短一些 { cacheTime = 2;//未知道操作何表时,只缓存2分钟(比如存储过程等语句) } switch (action) { case AopEnum.ExeMDataTableList: if (IsCanCache(aopInfo.TableList)) { JsonHelper js = new JsonHelper(false, false); foreach (MDataTable table in aopInfo.TableList) { js.Add(table.TableName, table.ToJson(true, true, RowOp.IgnoreNull)); } js.AddBr(); _MemCache.Set(key, js.ToString(), cacheTime); } break; case AopEnum.Select: case AopEnum.ExeMDataTable: if (IsCanCache(aopInfo.Table)) { _MemCache.Set(key, aopInfo.Table.ToJson(true, true, RowOp.IgnoreNull), cacheTime); } break; case AopEnum.ExeScalar: _MemCache.Set(key, aopInfo.ExeResult, cacheTime); break; case AopEnum.Fill: _MemCache.Set(key, aopInfo.Row, cacheTime); break; case AopEnum.GetCount: _MemCache.Set(key, aopInfo.RowCount, cacheTime); break; } }