Step 2: Caching the AdvancedB2B Direct store catalog pages

This section of the tutorial is designed to illustrate through examples, the steps involved in caching the AdvancedB2B Direct store catalog pages. At the end of this section you will be able to:

Caching the AdvancedB2B store catalog pages

Web page output of the AdvancedB2B store is driven by JSP processing. Each page is composed of one or more JSP invocations. In order to cache the servlet or JSP results, we need to define a cache policy in the cachespec.xml file. Each cacheable object must be defined as a cache-entry element and each cache-entry must specify certain basic information that the dynamic cache uses.The following steps show how to define a cache policy to cache the page output for the StoreCatalogDisplay command.

Caching as a full page or page fragments

  1. Invoke the URL https://hostname/webapp/wcs/stores/servlet/StoreCatalogDisplay?langId=-1&storeId=10051&catalogId=10101. See the following image for an example of what will be displayed.Example image of the AdvancedB2BDirect store home page.
  2. Determine whether or not you should cache as a full page or page fragment, by seeing Caching strategy.

    Note: For the B2BAdvanced Direct store, the page output for the StoreCatalogDisplay command is dependent on the user's information, (for example, different roles see different versions of each page) therefore it is not possible to cache the page output as a whole, and fragment caching is used.

  3. Determine which JSP is being invoked by the StoreCatalogDisplay command. To do this, look up the properties column in the VIEWREG table by typing the following in a DB2 command line:
    db2 select properties from viewreg where 
            storeent_id=10051 and viewname='StoreCatalogDisplayView'
    

    You should see output similar to the following:

    PROPERTIES
    ----------------------------------------------------------------------------------------------------
    docname=ShoppingArea/CatalogSection/CategorySubsection/StoreCatalogDisplay.jsp
    1 record(s) selected.
    
    The JSP page being invoked is /AdvancedB2BDirect/ShoppingArea/CatalogSection/CategorySubsection/StoreCatalogDisplay.jsp because the store directory is AdvancedB2BDirect.
  4. In your browser, select View > Source, and examine the source of the StoreCatalogDisplay.jsp page. You should see that it includes the following JSP pages:
    • AdvancedB2BDirect/include/JSTLEnvironmentSetup.jspf
    • AdvancedB2BDirect/include/LayoutContainerTop.jspf
      • AdvancedB2BDirect/include/HeaderDisplay.jsp
        • AdvancedB2BDirect/include/styles/style/CachedHeaderDisplay.jsp
      • AdvancedB2BDirect/include/SidebarDisplay.jsp
        • AdvancedB2BDirect/include/styles/style/CachedSidebarDisplay.jsp
    • AdvancedB2BDirect/ShoppingArea/CatalogSection/CatagorySubsection/CachedStoreCatalogDisplay.jsp

The next section examines whether the JSP pages can be cached. If so, you need to define a cache entry for each JSP page.

Defining cache policies for the JSP pages

In order to define cache entries to cache the JSP page result, the JSP pages need to be examined in detail.

  1. Open the StoreCatalogDisplay.jsp page.Example image of AdvancedB2BDirect store from StoreCatalogDisplay.jsp page. You should see that it does the following:
    • Displays a Current Order spot.
    • Displays an E-Marketing spot.
    • Displays a Browse Catalog button.
  2. Open the HeaderDisplay.jsp page. You should see that it does the following:Example image of HeaderDisplay.jsp page fragment.
  3. Open the SidebarDisplay.jsp page.

    For registered users, the page displays the following:

    Example image of SidebarDisplay.jsp page fragment for registered users.

    For registered users with a Buyer (buy-side) role, the SidebarDisplay. jsp page displays as follows:

    Example image of SidebarDisplay.jsp page fragment for Buyer (buy-side) users.

    The Buyer (buy-side) role will see the RFQ list option on the sidebar. Guest users cannot access the AdvancedB2B store, since it requires all users to logon for authentication.

As you can see, different variations of the page output from StoreCatalogDisplay.jsp, HeaderDisplay.jsp and SidebarDisplay.jsp are all based on the user's information, such as user's type and user's role. If you want to cache the header, sidebar, and the rest of the StoreCatalogDisplay page, you must use the user's information as part of the cache ID.

Considering marketing campaigns

In the AdvancedB2B Direct store, you can create campaigns based on the accounts to which you belong. See Creating a campaign for details.

The StoreCatalogDisplay.jsp displays the ConfigurableStoreDisplay e-Marketing spot and since an e-Marketing spot should not really be cached, then you should change the JSP page, move it to a separate JSP page, and use an include action to include it. Also the e-Marketing spot bean com.ibm.commerce.marketing.beans.EMarketingSpot needs the e-Marketing Spot name and catalog ID, therefore we need to pass them as parameters.

This is shown in the following example:

<c:import url="${jspStoreDir}include/MiniProductESpot.jsp" > ... <c:param name="catalogId" value="${catalogId }" /> ... <c:param name="emsName" value="ConfigurableStoreDisplay"/> </c:import>

Defining cache entries and cache IDs

Now we have finished changing the JSP files, we can define cache entries to get these JSP pages cached. Note: StoreCatalogDisplay.jsp should not be cached since it contains logic to determine the user's information. The pages you must cache are:

To cache the pages:

  1. Set up the cache-entry for the CachedHeaderDisplay.jsp file as shown in the following:
    <cache-entry>
       <class>servlet</class>
       <name>/AdvancedB2BDirect/include/CachedHeaderDisplay.jsp</name>
       <property name="save-attributes">false</property>
    
       <cache-id>
     <component id="storeId" type="parameter">
      <required>true</required>
     </component>
     <component id="catalogId" type="parameter">
      <required>true</required>
     </component>
     <component id="userType" type="parameter">
      <required>true</required>
     </component>
    <component id="liveHelp" type="parameter"> <required>true</required> </component> <component id="rfqLinkDisplayed" type="parameter"> <required>true</required> </component> <component id="DC_lang" type="attribute"> <required>true</required> </component> </cache-id> </cache-entry>

    Note: The request attribute DC_lang is defined as part of the cache ID because the AdvancedB2B Direct store supports multiple languages. However, we cannot use the parameter langId because it is not a mandatory parameter.

  2. Set up the cache entries for the CachedSidebarDisplay.jsp file as shown in the following:
    <cache-entry>
      <class>servlet</class>
      <name>/AdvancedB2BDirect/include/CachedSidebarDisplay.jsp</name>
      <property name="save-attributes">false</property>
    
      <cache-id>
     <component id="storeId" type="parameter">
      <required>true</required>
     </component>
     <component id="catalogId" type="parameter">
      <required>true</required>
     </component>
     <component id="userType" type="parameter">
      <required>true</required>
     </component>
     <component id="userState" type="parameter">
      <required>true</required>
     </component>
     <component id="liveHelp" type="parameter">
      <required>true</required>
     </component>
     <component id="DC_lang" type="attribute">
      <required>true</required>
     </component>
      </cache-id>
    </cache-entry>
    
  3. Set up the CachedStoreCatalogDisplay.jsp file as shown in the following:
    <cache-entry>
      <class>servlet</class>
      <name>/AdvancedB2BDirect/ShoppingArea/CatalogSecion/CategorySubsection/CachedStoreCatalogDisplay.jsp</name>
      <property name="save-attributes">false</property>
    
      <cache-id>
     <component id="storeId" type="parameter">
      <required>true</required>
     </component>
     <component id="catalogId" type="parameter">
      <required>true</required>
     </component>
     <component id="displayApproverLink" type="parameter">
      <required>true</required>
     </component>
     <component id="DC_lang" type="attribute">
      <required>true</required>
     </component>
      </cache-id>
    </cache-entry>
    

Defining dependency IDs

After the cache entries are defined, then we need to define dependency IDs for the entries. Dependency ID rules should be defined with cache invalidation in mind. That is, consider what could cause the cached JSP content to become invalid and which JSP pages need to be invalidated as a result. Examples of events that could cause cache content to become invalid include:

For example, if the store administrator wants all the cached JSP pages to be invalidated when the store is closed, then all the JSP pages would need to have a grouping ID (dependency ID). When the command com.ibm.commerce.store.commands.StoreCloseCmdImpl is invoked, it will invalidate all the cache entries associated with that dependency ID.

In this case, create a dependency ID like the following:

<dependency-id>storeId
  <component id="storeId" type="parameter">
    <required>true</required>
  </component>
</dependency-id>
Note: Similar dependency IDs can be created for catalog information such as catalog ID, category ID, and product ID.

Now consider a contract. For the default AdvancedB2B Direct store, there are four contracts deployed when the store is published, two for each organization. In this example, the user can only be eligible for a maximum of two contracts. Create the dependency IDs as follows with DC_cont0 and DC_cont1 as the attribute IDs:

<dependency-id>contracts
  <component id="DC_cont" type="attribute" ignore-value="true">
    <required>true</required>
  </component>
</dependency-id>
<dependency-id>contractId
  <component id="DC_cont0" type="attribute">
    <required>true</required>
  </component>
</dependency-id>

<dependency-id>contractId
  <component id="DC_cont1" type="attribute">
    <required>true</required>
  </component>
</dependency-id>

Displaying cache information

Notes:

You can access the cache monitor Web application using a Web browser with the following Web address:

http://host_name:port/cachemonitor

However, for a more secure access, it is recommended that you access the Administration host machine:

https://admin_host_name:port/cachemonitor

For example, if the virtual host VH_instance_name_admin is used for installing the Cache Monitor, then the Cache Monitor can be accessed as:

https://admin_host_name:8002/cachemonitor

The location for the sample cachespec.xml file for the AdvancedB2BDirect store is WC_install/samples/dynacache/AdvancedB2BDirect/cachespec.xml.

After defining the cache entries, you can use the cache monitor to:


Summary

In this section of the tutorial, you were shown how to:


Feedback