/// <summary> /// Cache Channel /// </summary> /// <param name="tableName">tableName</param> /// <param name="cacheKey">cacheKey</param> /// <param name="func">Func<object></param> /// <returns></returns> private static object CacheChannel(string tableName, string cacheKey, Func <object> func) { /** * author:qixiao * create:2017-8-7 22:47:13 * Howw to judge a cache lose efficacy when we update the table data ? * we add another cache name changeCache, let key = tableName,expire time default ,like 1. * once we gain data from cache , validate changeCache has any value not null.if it is ,regard value changed,we should gain table data renew not from cache. * if it is null , regard as unchanged, if cacheCache expire ,dataCache expired too,we can gain cache relieved * */ if (HttpRuntimeCache_Helper_DG.Cache_Get(tableName) == null) { object cacheValue = HttpRuntimeCache_Helper_DG.Cache_Get(cacheKey); if (cacheValue != null) { return(cacheValue); } } //Execute Action object result = func(); HttpRuntimeCache_Helper_DG.Cache_Add(cacheKey, result); HttpRuntimeCache_Helper_DG.Cache_Delete(tableName); return(result); }
/// <summary> /// TableConstructionCache /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cacheKey"></param> /// <param name="func"></param> /// <returns></returns> internal static T TableConstructionCache <T>(string cacheKey, Func <T> func) where T : class { string hashKey = cacheKey.GetHashCode().ToString(); object cacheValue = HttpRuntimeCache_Helper_DG.Cache_Get(hashKey); if (cacheValue != null) { return(cacheValue as T); } cacheValue = func(); HttpRuntimeCache_Helper_DG.Cache_Add(hashKey, cacheValue, 1440); return(cacheValue as T); }
public bool Insert(string tableName, IDictionary <string, object> keyValueDic) { return(this.CommonFlow(tableName, () => { StringBuilder builder_front = new StringBuilder(); StringBuilder builder_behind = new StringBuilder(); List <SqlParameter> sqlParameterList = new List <SqlParameter>(); builder_front.Append("INSERT INTO "); builder_front.Append(tableName); builder_front.Append(" ("); builder_behind.Append(" VALUES ("); foreach (TableFeildInfo feild in this.TableInfo.TableFildsInfoList) { if (feild.IsIdentity) { goto checkEnd; } /** * 1.search table feild similar in keyValueDic.Keys * 2.get correct * */ var keyValueData = RecognitFeildFromDataDictionary(feild.FeildName, keyValueDic); if (keyValueData != null) { builder_front.Append(feild.FeildName); builder_front.Append(","); builder_behind.Append("@"); builder_behind.Append(feild.FeildName); builder_behind.Append(","); sqlParameterList.Add(new SqlParameter("@" + feild.FeildName, keyValueData.Value)); } else { // if feild cannot be null if (feild.Nullable == 0) { builder_front.Append(feild.FeildName); builder_front.Append(","); builder_behind.Append("@"); builder_behind.Append(feild.FeildName); builder_behind.Append(","); sqlParameterList.Add(new SqlParameter("@" + feild.FeildName, TypeConvert_Helper_DG.SqlDbTypeToCsharpTypeDefaultValue(feild.Type))); } } checkEnd: //the end if (this.TableInfo.TableFildsInfoList.LastOrDefault() == feild) { builder_front.Remove(builder_front.Length - 1, 1); builder_front.Append(")"); builder_behind.Remove(builder_behind.Length - 1, 1); builder_behind.Append(")"); } } //Generate SqlStatement string sql = builder_front.Append(builder_behind.ToString()).ToString(); this.SqlStatement = sql; HttpRuntimeCache_Helper_DG.Cache_Add(tableName, 1); this.Message = "add success"; return ExecuteNonQuery(sql, System.Data.CommandType.Text, sqlParameterList.ToArray()) > 0;; })); }