/// <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); }