protected void PageChanged(object sender, DataGridPageChangedEventArgs e) { products.CurrentPageIndex = e.NewPageIndex; // Get the search terms from the query string string searchKey = WebComponents.CleanString.InputText(Request["keywords"], 100); if (searchKey != ""){ // Create a data cache key string cacheKey = "search" + searchKey; // Check if the objects are in the cache if(Cache[cacheKey] != null){ products.DataSource = (IList)Cache[cacheKey]; }else{ // If that data is not in the cache then use the business logic tier to fetch the data Product product = new Product(); IList productsBySearch = product.GetProductsBySearch(searchKey); // Store the results in a cache Cache.Add(cacheKey, productsBySearch, null, DateTime.Now.AddHours(12), Cache.NoSlidingExpiration , CacheItemPriority.High, null); products.DataSource = productsBySearch; } // Databind the data to the controls products.DataBind(); } }
/// <summary> /// Rebind control /// </summary> protected void PageChanged(object sender, DataGridPageChangedEventArgs e) { //reset index searchList.CurrentPageIndex = e.NewPageIndex; //get category id string keywordKey = Request.QueryString["keywords"]; //bind data Product product = new Product(); searchList.DataSource = product.GetProductsBySearch(keywordKey); searchList.DataBind(); }
/// <summary> /// This method acts as a proxy between the web and business components to check whether the /// underlying search result has already been cached. /// </summary> /// <param name="text">Search Text</param> /// <returns>List of ProductInfo from Cache or Business component</returns> public static IList<ProductInfo> GetProductsBySearch(string text) { Product product = new Product(); if (!enableCaching) return product.GetProductsBySearch(text); string key = "product_search_" + text; IList<ProductInfo> data = (IList<ProductInfo>)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 = product.GetProductsBySearch(text); // Create a AggregateCacheDependency object from the factory AggregateCacheDependency cd = DependencyFacade.GetProductDependency(); // Store the output in the data cache, and Add the necessary AggregateCacheDependency object HttpRuntime.Cache.Add(key, data, cd, DateTime.Now.AddHours(productTimeout), Cache.NoSlidingExpiration, CacheItemPriority.High, null); } return data; }