Exemplo n.º 1
0
        public static CacheInfo CreateCacheInfo(CacheableAttribute cacheInfoAtt, MethodInfo methodInfo, Delegate funcInstanc, string key)
        {
            var name = string.Format("{0}.{1}",
                                     methodInfo.ReflectedType.Name,
                                     methodInfo.Name);
            string parameterPartUniqueKey = string.Empty;

            foreach (var item in methodInfo.GetParameters())
            {
                parameterPartUniqueKey += "_" + item.ParameterType.Name;
            }
            var uniqueKeyInServerLevel = name + parameterPartUniqueKey;
            var currentCacheInfo       = CacheInfoDic[key] = new CacheInfo()
            {
                Name = name,
                AutoRefreshInterval = cacheInfoAtt.ExpireCacheSecondTime == 0 ? cacheInfoAtt.AutoRefreshInterval : cacheInfoAtt.ExpireCacheSecondTime,
                MethodInfo          = methodInfo,
                BasicKey            = int.Parse(key),
                CreateDateTime      = DateTime.Now,
                Func = funcInstanc,
                EnableUseCacheServer               = cacheInfoAtt.EnableUseCacheServer,
                UniqueKeyInServerLevel             = uniqueKeyInServerLevel,
                EnableToFetchOnlyChangedDataFromDB = cacheInfoAtt.EnableToFetchOnlyChangedDataFromDB,
                NameOfNavigationPropsForFetchingOnlyChangedDataFromDB = cacheInfoAtt.NameOfNavigationPropsForFetchingOnlyChangedDataFromDB,
                CacheRefreshingKind = cacheInfoAtt.EnableAutomaticallyAndPeriodicallyRefreshCache ? CacheRefreshingKind.Slide : CacheRefreshingKind.OnRequestToGetCache,
                DisableToSyncDeletedRecord_JustIfEnableToFetchOnlyChangedDataFromDB = cacheInfoAtt.DisableToSyncDeletedRecord_JustIfEnableToFetchOnlyChangedDataFromDB,
                DisableCache            = cacheInfoAtt.DisableCache,
                EnableSaveCacheOnHDD    = cacheInfoAtt.EnableSaveCacheOnHDD,
                EnableCoreSerialization = cacheInfoAtt.EnableCoreSerialization
            };

            if (currentCacheInfo.CacheRefreshingKind == CacheRefreshingKind.OnRequestToGetCache)
            {
                currentCacheInfo.CacheRefreshingKind = cacheInfoAtt.CacheRefreshingKind;
            }

            var parames = methodInfo.GetParameters();

            if (typeof(IQueryable).IsAssignableFrom(methodInfo.ReturnType) && parames.Length > 0 && typeof(IQueryable).IsAssignableFrom(parames[0].ParameterType))
            {
                currentCacheInfo.IsFunctionalCache = false;
            }
            return(currentCacheInfo);
        }