public void Add(string groupName, string key, object value) { CacheManager cacheManager = GetCacheManagerByGroupName(groupName); if (cacheManager != null) { LocalCachePolicy policy = cacheSettingManager.GetLocalCachePolicy(groupName); if (policy != null && policy.AbsoluteExpirationTimeInSecond > 0) { cacheManager.Add(key, value, CacheItemPriority.Normal, null, new AbsoluteTime(DateTime.Now.AddSeconds(policy.AbsoluteExpirationTimeInSecond))); } else { cacheManager.Add(key, value); } } }
internal DictionaryConfigurationSource GetCachingConfiguration(string policyName) { DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource(); CacheManagerSettings cachingConfiguration = new CacheManagerSettings(); cachingConfiguration.DefaultCacheManager = policyName; Type nullBackingStoreType = Type.GetType(new NullBackingStore().GetType().AssemblyQualifiedName); CacheStorageData cacheStorageData = new CacheStorageData("MyCACHE", nullBackingStoreType); cachingConfiguration.BackingStores.Add(cacheStorageData); LocalCachePolicy policy = cacheSettingManager.GetLocalCachePolicy(policyName); CacheManagerData cacheManagerData = new CacheManagerData(policyName, policy.ExpiredSeconds, policy.MaxElements, 10, "MyCACHE"); cachingConfiguration.CacheManagers.Add(cacheManagerData); configurationSource.Add(CacheManagerSettings.SectionName, cachingConfiguration); return(configurationSource); }