Catalog Cache and Campaign Cache Refresh Code Sample for a Commerce Server 2002 ASP.NET C# Site (828651)



The information in this article applies to:

  • Microsoft Commerce Server 2002
  • Microsoft Commerce Server 2002 SP1

SUMMARY

By default, all blank sites that are included with Microsoft Commerce Server 2002 (including VB.pup, CSharp.pup, and Blank.pup) do not have cache refresh code implemented.

This article contains Microsoft ASP.NET C# sample code to refresh the Catalog cache, the Discount cache, and the Advertisement cache.
  • For the Microsoft Visual Basic .NET sample code, see the Retail2002 site in Microsoft Commerce Server 2002 Software Development Kit (SDK).
  • For C# profile refresh sample code, click the following article number to view the article in the Microsoft Knowledge Base:

    815700 How to Create Code for Profile Refresh in Visual C# .NET

  • For Microsoft Visual Basic .NET profile refresh sample code, click the following article number to view the article in the Microsoft Knowledge Base:

    816081 How to Create Code for the ProfileRefresh Subroutine in Visual Basic .NET

    For the Visual Basic .NET profile refresh sample code, you can also see the Retail2002 site in Microsoft Commerce Server 2002 SDK.

MORE INFORMATION

To add the cache refresh code to a blank site, follow these steps:
  1. In the Web.config file, add the following tags under the Caches tag that appears under the CommerceServer tag:
                <cache
                    name="Advertising"
                    type="Advertising"
                    refreshInterval="900"
                    retryInterval="30" />
    
                <cache
                    name="Discounts"
                    type="Discounts"
                    refreshInterval="0"
                    retryInterval="30" />
    
                <cache
                    name="QueryCatalogInfoCache"
                    type="QCI"
                    loaderProgId="Commerce.LRUCacheFlush"
                    refreshInterval="0"
                    retryInterval="300"
                    maxSize="10000">
                        <config key="TableName" value="CatalogCache_Virtual_Directory" />
                </cache>
  2. Add the following tags under the Pipelines tag that appears under the CommerceServer tag.

    Note For the pipelines that this code defines, you must have the corresponding pipeline configuration files in the Pipelines folder.
                <pipeline
                    name="advertising"
                    path="pipelines\advertising.pcf"
                    transacted="false"
                    type="CSFPipeline" />
    
                <pipeline
                    name="discounts"
                    path="pipelines\discounts.pcf"
                    transacted="false"
                    type="CSFPipeline" />
            
            				<pipeline
                    name="basket"
                    path="pipelines\basket.pcf"
                    transacted="false"
                    type="OrderPipeline"
                    loggingEnabled="true" />
    
                <pipeline
                    name="checkout"
                    path="pipelines\checkout.pcf"
                    transacted="true"
                    type="OrderPipeline"
                    loggingEnabled="true" />
    
                <pipeline
                    name="total"
                    path="pipelines\total.pcf"
                    transacted="false"
                    type="OrderPipeline"
                    loggingEnabled="true" />
    
                <pipeline
                    name="recordevent"
                    path="pipelines\recordevent.pcf"
                    transacted="false"
                    type="CSFPipeline" />
  3. Add the following tags under the CommerceServer tag:
    		<contentSelection>
    			<add name="advertising" cacheName="advertising" selectionPipeline="advertising" eventPipeline="recordEvent" redirectUrl="./redir.aspx"/>
    			<add name="discounts" cacheName="discounts" selectionPipeline="discounts" eventPipeline="recordEvent" redirectUrl="./redir.aspx"/>
    		</contentSelection>
  4. Modify the BDRefresh.aspx.cs file as follows.

    Note In the following sample code, namespace is NorthWindTraders. You must replace "NorthWindTraders" with your site name.
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    
    using Microsoft.CommerceServer.Runtime;
    using Microsoft.CommerceServer.Runtime.Caching;
    
    namespace NorthWindTraders
    {
    	/// <summary>
    	/// 
    =============================================================================
    	/// BDRefresh.aspx
    	/// Refresh all caches
    	///
    	/// Commerce Server 2002 Solution Sites 1.0
    	/// 
    -----------------------------------------------------------------------------
    	///  This file is part of Microsoft Commerce Server 2002
    	///
    	///  Copyright (C) 2002 Microsoft Corporation.  All rights reserved.
    	///
    	/// This source code is intended only as a supplement to Microsoft
    	/// Commerce Server 2002 and/or on-line documentation.  See these other
    	/// materials for detailed information regarding Microsoft code samples.
    	///
    	/// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
    	/// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    	/// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
    	/// PARTICULAR PURPOSE.
    	/// 
    =============================================================================
    	///
    	/// The BDRefresh.asp page is typically responsible for refreshing the following
    	/// caches:
    	///
    	///     - Shipping Manager cache
    	///     - Catalog cache(s)
    	///     - HTML fragment cache
    	///
    	/// For more information on how to refresh a particular cache, refer to the
    	/// documentation for the CacheManager.RefreshCache() method.
    	///
    	/// The following code is supplied as a framework for making this page function
    	/// correctly.  It does not actually refresh any cache(s).  Refer to the
    	/// BDRefresh.asp page supplied in the Retail and Supplier Solution Sites for
    	/// more information on how this page refreshes the caches created for the
    	/// sites.
    	/// </summary>
    	public class BDRefresh : System.Web.UI.Page
    	{
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    			string sCacheName;
    
    			CommerceCache cache;
    			CommerceCacheCollection caches;
    
    			sCacheName = Request.QueryString["cache_name"];
    
    			try 
    			{
    				caches = CommerceContext.Current.Caches;
    
    				if (sCacheName == "CatalogCache")
    				{
    					cache = caches["QueryCatalogInfoCache"];
    					if (cache!=null)
    					{
    						cache.Refresh();
    						CommerceContext.Current.CatalogSystem.Refresh();
    					}
    				}
    				else
    				{
    					cache = caches[sCacheName];
    					if (cache!=null)
    					{
    						cache.Refresh();
    					}
    				}
    
    				Response.Write("");
    			}
    			catch(Exception ex) 
    			{
    				Response.Write("Error Number:  1     Error Source:  " + ex.Source + "     Error 
    Message:  " + ex.Message);
    			}
    		}
    
    		#region Web Form Designer generated code
    		override protected void OnInit(EventArgs e)
    		{
    			//
    			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
    			//
    			InitializeComponent();
    			base.OnInit(e);
    		}
    		
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		private void InitializeComponent()
    		{    
    			this.Load += new System.EventHandler(this.Page_Load);
    		}
    		#endregion
    	}
    }
    
  5. Modify the BDRefresh.asp file as follows:
    <%
    Response.Redirect("BDRefresh.aspx?") & Request.ServerVariables("QUERY_STRING")
    %>
    
  6. Rebuild the project.

Modification Type:MajorLast Reviewed:10/31/2003
Keywords:kbhowto KB828651 kbAudDeveloper