/// <summary> /// 更新数据缓存。 /// </summary> /// <param name="info"></param> private void UpdateDataCache(InterceptCallInfo info) { //判断是否加了 CacheSupportAttribute 特性 if (info.Member.IsDefined <CacheSupportAttribute>()) { var attr = info.Member.GetCustomAttribute <CacheSupportAttribute>(); var relationTypes = info.Member.GetCustomAttributes <CacheRelationAttribute>().Select(s => s.RelationType).ToList(); var returnType = (info.Member as MethodInfo).ReturnType; var cacheMgr = CacheManagerFactory.CreateManager(); var cacheKey = GetCacheKey(info); if (loadFromCache) { loadFromCache = false; return; } var method = MthCacheAdd.MakeGenericMethod(info.ReturnType); method.FastInvoke(cacheMgr, cacheKey, info.ReturnValue, TimeSpan.FromSeconds(attr.Expired), null); CacheKeyManager.AddKeys(returnType, cacheKey); if (relationTypes.Count > 0) { CacheKeyManager.AddKeys(relationTypes, cacheKey); } } }
/// <summary> /// 更新数据缓存。 /// </summary> /// <param name="info"></param> private void UpdateDataCache(InterceptCallInfo info) { //判断是否加了 CacheSupportAttribute 特性 if (info.Member.IsDefined <CacheSupportAttribute>()) { var attr = info.Member.GetCustomAttribute <CacheSupportAttribute>(); var relationTypes = info.Member.GetCustomAttributes <CacheRelationAttribute>().Select(s => s.RelationType).ToList(); var returnType = (info.Member as MethodInfo).ReturnType; var cacheMgr = CacheManagerFactory.CreateManager(); var cacheKey = GetCacheKey(info); try { cacheMgr.Add(cacheKey, info.ReturnValue, TimeSpan.FromSeconds(attr.Expired)); CacheKeyManager.AddKeys(returnType, cacheKey); if (relationTypes.Count > 0) { CacheKeyManager.AddKeys(relationTypes, cacheKey); } } catch (Exception exp) { } } }