public void ItemsGetRemovedFromCacheAfterExpiration() { Assert.IsNull(cache.GetData("key")); DataBackingStore backingStore = CreateDataBackingStore(); Assert.AreEqual(0, backingStore.Load().Count); AbsoluteTime threeSecondExpiration = new AbsoluteTime(DateTime.Now + TimeSpan.FromSeconds(3.0)); lock (callbackLock) { cache.Add("key", "value", CacheItemPriority.NotRemovable, new RefreshAction(), threeSecondExpiration); Assert.IsNotNull(cache.GetData("key")); Hashtable oneEntryHashTable = backingStore.Load(); Assert.AreEqual(1, oneEntryHashTable.Count); Monitor.Wait(callbackLock, 15000); Assert.IsTrue(wasCalledBack); } object removedItem = cache.GetData("key"); Assert.IsNull(removedItem); Hashtable emptyHashTable = backingStore.Load(); Assert.AreEqual(0, emptyHashTable.Count); }
/// <summary> /// 添加缓存 /// by Hades.Gao /// </summary> /// <param name="cKey">缓存关键字</param> /// <param name="obj">缓存对象</param> /// <param name="_CacheTimeOut">过期时间,以秒作单位</param> public void AddCache(string cKey, object obj, int _CacheTimeOut) { try { TimeSpan refreshTime = new TimeSpan(0, 0, _CacheTimeOut); AbsoluteTime expireTime = new AbsoluteTime(refreshTime); if (!Object.Equals(_DataCacheManager, null)) _DataCacheManager.Add(cKey, obj, CacheItemPriority.Normal, null, expireTime); } catch (Exception ex) { this.LogInfo("添加缓存时出错:" + ex.Message + "\r\nTargetSite:" + ex.TargetSite + "\r\nKey:" + cKey + "\r\nObjectType:" + obj.GetType() + "\r\nObject:" + obj.ToString() + "\r\nTimeOut:" + _CacheTimeOut.ToString()); } }
public List<Product> GetProductData(out string cacheStatus) { cacheProductData = EnterpriseLibraryContainer.Current.GetInstance<ICacheManager>(); listProducts = (List<Product>)cacheProductData["ProductDataCache"]; cacheStatus = "Employee Information is Retrived from Cache"; LetsShopImplementation ls = new LetsShopImplementation(); CacheFlag = true; if (listProducts == null) { //Database _db = EnterpriseLibraryContainer.Current.GetInstance<Database>("LetsShopConnection"); //listProducts = LetsShopImplementation ls = new LetsShopImplementation(); listProducts = ls.GetProducts(); AbsoluteTime CacheExpirationTime = new AbsoluteTime(new TimeSpan(1, 0, 0)); cacheProductData.Add("ProductDataCache", listProducts, CacheItemPriority.High, null, new ICacheItemExpiration[] { CacheExpirationTime }); cacheStatus = "Product Info is Added in cache"; CacheFlag = false; } return listProducts; }
public static void RegisterWith( IUnityContainer container ) { container.RegisterType<ICssScriptCompressionService, MicrosoftMinifierCssCompresionService>(); container.RegisterType<IJavaScriptCompressionService, MicrosoftMinifierJavascriptCompressionService>(); container.RegisterType<ICssProviderService, CssConfigurationProviderService>();//(CSS_COMPRESSION_SERVICE_NAME); container.RegisterType<IJavaScriptProviderService, JavaScriptConfigurationProviderService>();//(JS_COMPRESSION_SERVICE_NAME); var scriptCacheExpiration = new AbsoluteTime(DateTime.Now.Add(AppSettings.DefaultCacheAbsoluteTimeExpiration)); /* container.RegisterType<Services.ICssProviderService, Services.Implementations.CachedCssProviderSerive>( new InjectionConstructor( new ResolvedParameter<Services.ICssProviderService>(CSS_COMPRESSION_SERVICE_NAME), new ResolvedParameter<ICacheManager>(DEFAULT_CACHE_MANAGER), scriptCacheExpiration)); container.RegisterType<Services.IJavaScriptProviderService, Services.Implementations.CachedJavaScriptProviderService>( new InjectionConstructor( new ResolvedParameter<Services.IJavaScriptProviderService>(JS_COMPRESSION_SERVICE_NAME), new ResolvedParameter<ICacheManager>(DEFAULT_CACHE_MANAGER), scriptCacheExpiration)); */ }
private ICacheItemExpiration[] GetCacheExpirations() { ICacheItemExpiration[] cachingExpirations = new ICacheItemExpiration[2]; cachingExpirations[0] = new AbsoluteTime(new TimeSpan(0, 0, ConvertExpirationTimeToSeconds(absoluteExpiration))); cachingExpirations[1] = new SlidingTime(new TimeSpan(0, 0, ConvertExpirationTimeToSeconds(slidingExpiration))); return cachingExpirations; }
/// <summary>TBD</summary> private static void PopulateApplicationCache() { ICacheManager appCache = CacheFactory.GetCacheManager(); //Common Expiration time, used by cached data which is built from tables that refresh as part of the SQL Server scheduled job AbsoluteTime expiry = new AbsoluteTime(new TimeSpan(0, 3, 30, 0)); if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.ADDepartments))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.ADDepartments), GetADDepartments(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.ADOffices))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.ADOffices), GetADOffices(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.MarketDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.MarketDataSetType), GetMarkets(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.MediaFormDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.MediaFormDataSetType), GetMediaForms(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.NewMediaFormDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.NewMediaFormDataSetType), GetNewMediaForms(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.NewMediaTypeDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.NewMediaTypeDataSetType), GetNewMediaTypes(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.MediaTypeDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.MediaTypeDataSetType), GetMediaTypes(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.AEDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.AEDataSetType), GetAEs(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.ConsolidatedAdvertiserType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.ConsolidatedAdvertiserType), GetConsolidatedAdvertisers(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.AgencyDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.AgencyDataSetType), GetAgencies(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.AdvertiserDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.AdvertiserDataSetType), GetAdvertisers(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.AppDefaultDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.AppDefaultDataSetType), GetAppDefaults(), CacheItemPriority.High, null, new ICacheItemExpiration[] { new AbsoluteTime(new TimeSpan(0, 12, 0, 0)) }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.ContractLineYearsDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.ContractLineYearsDataSetType), GetContractLineItemYears(), CacheItemPriority.High, null, new ICacheItemExpiration[] { new AbsoluteTime(new TimeSpan(0, 12, 0, 0)) }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.ProfitCenterDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.ProfitCenterDataSetType), GetProfitCenters(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.ParentProductClassDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.ParentProductClassDataSetType), GetParentProductClasses(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.ProductClassDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.ProductClassDataSetType), GetProductClasses(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.ProductClassDLDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.ProductClassDLDataSetType), GetProductClassesDL(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.StationDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.StationDataSetType), GetStations(), CacheItemPriority.High, null, new ICacheItemExpiration[] { expiry }); } if (!appCache.Contains(Enum.GetName(typeof(DataSetType), DataSetType.UploadedByDataSetType))) { appCache.Add(Enum.GetName(typeof(DataSetType), DataSetType.UploadedByDataSetType), GetUploadedBy(), CacheItemPriority.High, null, new ICacheItemExpiration[] { new AbsoluteTime(new TimeSpan(0, 0, 30, 0)) }); } }
private ICacheItemExpiration[] GetCacheExpirations() { CachingStoreProviderData cacheStorageProviderData = GetCacheStorageProviderData(); ICacheItemExpiration[] cachingExpirations = new ICacheItemExpiration[2]; cachingExpirations[0] = new AbsoluteTime(new TimeSpan(0, 0, ConvertExpirationTimeToSeconds(cacheStorageProviderData.AbsoluteExpiration))); cachingExpirations[1] = new SlidingTime(new TimeSpan(0, 0, ConvertExpirationTimeToSeconds(cacheStorageProviderData.SlidingExpiration))); return cachingExpirations; }