/// <summary> /// Method to retrieve and cache category name by its ID /// </summary> /// <param name="categoryId">Category id</param> /// <returns>Category name</returns> public static string GetCategoryName(string categoryId) { Category category = new Category(); if (!enableCaching) { return(category.GetCategory(categoryId).Name); } string cacheKey = string.Format(CATEGORY_NAME_KEY, categoryId); // Check if the data exists in the data cache string data = (string)HttpRuntime.Cache[cacheKey]; if (data == null) { // Caching duration from Web.config int cacheDuration = int.Parse(ConfigurationManager.AppSettings["CategoryCacheDuration"]); // If the data is not in the cache then fetch the data from the business logic tier data = category.GetCategory(categoryId).Name; // Create a AggregateCacheDependency object from the factory AggregateCacheDependency cd = DependencyFacade.GetCategoryDependency(); // Store the output in the data cache, and Add the necessary AggregateCacheDependency object HttpRuntime.Cache.Add(cacheKey, data, cd, DateTime.Now.AddHours(cacheDuration), Cache.NoSlidingExpiration, CacheItemPriority.High, null); } return(data); }
/// <summary> /// This method acts as a proxy between the web and business components to check whether the /// underlying category has already been cached. /// </summary> /// <param name="categoryId">Category Id</param> /// <returns>CategoryInfo from Cache or Business component</returns> public static CategoryInfo GetCategory(string categoryId) { Category category = new Category(); if (!enableCaching) { return(category.GetCategory(categoryId)); } string key = "category_" + categoryId; CategoryInfo data = (CategoryInfo)HttpRuntime.Cache[key]; // Check if the data exists in the data cache if (data == null) { // If the data is not in the cache then fetch the data from the business logic tier data = category.GetCategory(categoryId); // Create a AggregateCacheDependency object from the factory AggregateCacheDependency cd = DependencyFacade.GetCategoryDependency(); // Store the output in the data cache, and Add the necessary AggregateCacheDependency object HttpRuntime.Cache.Add(key, data, cd, DateTime.Now.AddHours(categoryTimeout), Cache.NoSlidingExpiration, CacheItemPriority.High, null); } return(data); }
protected void Page_Load(object sender, EventArgs e) { GetControlStyle(); BindCategories(); // Select current category string categoryId = Request.QueryString["categoryId"]; if (!string.IsNullOrEmpty(categoryId)) { SelectCategory(categoryId); } // Add cache dependency this.CachePolicy.Dependency = DependencyFacade.GetCategoryDependency(); }