Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        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);
        }