Microsoft KB Archive/828651

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

Article ID: 828651

Article Last Modified on 10/31/2003

-

APPLIES TO


 * Microsoft Commerce Server 2002 Standard Edition
 * Microsoft Commerce Server 2002 Service Pack 1

-



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:   In the Web.config file, add the following tags under the Caches tag that appears under the CommerceServer tag: 



  </li>  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=&quot;advertising&quot; path=&quot;pipelines\advertising.pcf&quot; transacted=&quot;false&quot; type=&quot;CSFPipeline&quot; />

<pipeline name=&quot;discounts&quot; path=&quot;pipelines\discounts.pcf&quot; transacted=&quot;false&quot; type=&quot;CSFPipeline&quot; /> <pipeline name=&quot;basket&quot; path=&quot;pipelines\basket.pcf&quot; transacted=&quot;false&quot; type=&quot;OrderPipeline&quot; loggingEnabled=&quot;true&quot; />

<pipeline name=&quot;checkout&quot; path=&quot;pipelines\checkout.pcf&quot; transacted=&quot;true&quot; type=&quot;OrderPipeline&quot; loggingEnabled=&quot;true&quot; />

<pipeline name=&quot;total&quot; path=&quot;pipelines\total.pcf&quot; transacted=&quot;false&quot; type=&quot;OrderPipeline&quot; loggingEnabled=&quot;true&quot; />

<pipeline name=&quot;recordevent&quot; path=&quot;pipelines\recordevent.pcf&quot; transacted=&quot;false&quot; type=&quot;CSFPipeline&quot; /> </li>  Add the following tags under the CommerceServer tag: <contentSelection> <add name=&quot;advertising&quot; cacheName=&quot;advertising&quot; selectionPipeline=&quot;advertising&quot; eventPipeline=&quot;recordEvent&quot; redirectUrl=&quot;./redir.aspx&quot;/> <add name=&quot;discounts&quot; cacheName=&quot;discounts&quot; selectionPipeline=&quot;discounts&quot; eventPipeline=&quot;recordEvent&quot; redirectUrl=&quot;./redir.aspx&quot;/> </contentSelection> </li>  Modify the BDRefresh.aspx.cs file as follows.

Note In the following sample code, namespace is NorthWindTraders. You must replace &quot;NorthWindTraders&quot; 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 {   ///     ///

=
================================================================   /// 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 &quot;AS IS&quot; 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. ///    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[&quot;cache_name&quot;];

try {               caches = CommerceContext.Current.Caches;

if (sCacheName == &quot;CatalogCache&quot;) {                   cache = caches[&quot;QueryCatalogInfoCache&quot;]; if (cache!=null) {                       cache.Refresh; CommerceContext.Current.CatalogSystem.Refresh; }               }                else {                   cache = caches[sCacheName]; if (cache!=null) {                       cache.Refresh; }               }

Response.Write(&quot;&quot;); }           catch(Exception ex) {               Response.Write(&quot;Error Number:  1     Error Source:  &quot; + ex.Source + &quot;     Error Message:  &quot; + 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); }       ///         /// Required method for Designer support - do not modify /// the contents of this method with the code editor. ///        private void InitializeComponent {               this.Load += new System.EventHandler(this.Page_Load); }       #endregion } } </li>  Modify the BDRefresh.asp file as follows: <% Response.Redirect(&quot;BDRefresh.aspx?&quot;) & Request.ServerVariables(&quot;QUERY_STRING&quot;) %> </li> Rebuild the project.</li></ol>

Additional query words: CSharp; Catalog Cache Refresh; Campaign Refresh

Keywords: kbhowto KB828651

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.