示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string categoryId = Request.QueryString["categoryId"];

            if (!string.IsNullOrEmpty(categoryId))
            {
                // process Home Page link
                HtmlAnchor lnkHome = new HtmlAnchor();
                lnkHome.InnerText = "Home";
                lnkHome.HRef      = "~/Default.aspx";
                plhControl.Controls.Add(lnkHome);
                plhControl.Controls.Add(GetDivider());

                // Process Product page link
                HtmlAnchor lnkProducts = new HtmlAnchor();
                lnkProducts.InnerText = WebUtility.GetCategoryName(categoryId);
                lnkProducts.HRef      = string.Format(PRODUCTS_URL, categoryId);
                plhControl.Controls.Add(lnkProducts);
                string productId = Request.QueryString["productId"];
                if (!string.IsNullOrEmpty(productId))
                {
                    // Process Item page link
                    plhControl.Controls.Add(GetDivider());
                    HtmlAnchor lnkItemDetails = new HtmlAnchor();
                    lnkItemDetails.InnerText = WebUtility.GetProductName(productId);
                    lnkItemDetails.HRef      = string.Format(ITEMS_URL, categoryId, productId);
                    plhControl.Controls.Add(lnkItemDetails);
                }
            }

            // Add cache dependency
            this.CachePolicy.Dependency = DependencyFacade.GetItemDependency();
        }
        /// <summary>
        /// This method acts as a proxy between the web and business components to check whether the
        /// underlying item has already been cached.
        /// </summary>
        /// <param name="itemId">Item Id</param>
        /// <returns>ItemInfo from Cache or Business component</returns>
        public static ItemInfo GetItem(string itemId)
        {
            Item item = new Item();

            if (!enableCaching)
            {
                return(item.GetItem(itemId));
            }

            string   key  = "item_" + itemId;
            ItemInfo data = (ItemInfo)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 = item.GetItem(itemId);

                // Create a AggregateCacheDependency object from the factory
                AggregateCacheDependency cd = DependencyFacade.GetItemDependency();

                // Store the output in the data cache, and Add the necessary AggregateCacheDependency object
                HttpRuntime.Cache.Add(key, data, cd, DateTime.Now.AddHours(itemTimeout), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
            }
            return(data);
        }
 /// <summary>
 /// Add cache dependency
 /// </summary>
 protected void Page_Load(object sender, EventArgs e)
 {
     this.CachePolicy.Dependency = DependencyFacade.GetItemDependency();
 }