Feature Pack 5 or later

Setting up JSP snippet caching based on activity behavior

You can improve performance by caching an e-Marketing Spot at the storefront based on the activity behavior, which includes web activities and marketing content.

Before you begin

  • Install WebSphere Commerce Version 7 Feature Pack 5 or higher.
  • Enable the store-enhancements feature.

About this task

To set up this type of caching, dependency IDs are dynamically set to invalidate the cached JSP when the e-Marketing Spot definition changes. These definition changes can be caused by events such as web activity changes, default content changes, content changes, product changes, and category changes. The page time limit is set to invalidate the page at the next scheduled time that an activity is added or removed from the e-Marketing Spot. When the page is reloaded, the new set of active activities for the e-Marketing Spot is in effect.

Procedure

  1. Open the cachespec.xml cache configuration file in the following directory:
    • WebSphere Commerce DeveloperWCDE_installdir/workspace/Stores/WebContent/WEB-INF/
    • WebSphere Commerce EnterpriseWebSphere Commerce - ExpressWebSphere Commerce ProfessionalWC_eardir/Stores.war/WEB-INF/
  2. For each e-Marketing Spot JSP snippet in the store, include a cache entry similar to the following code.

    Ensure that the following are specified:

    • The do-not-consume property is true.
    • The do-not-cache property is true.
    • The metadatagenerator is specified as com.ibm.commerce.marketing.cache.EMarketingSpotMetaDataGenerator.
    <cache-entry>
    	<class>servlet</class>
    	<name>/Madisons/Snippets/Marketing/ESpot/ContentAreaESpot.jsp</name>		
    	<property name="do-not-consume">true</property>
    	<property name="do-not-cache">true</property>
    		<property name="save-attributes">false</property>
    		<cache-id>
    			<component id="emsName" type="parameter">
    				<required>false</required>
    			</component>
    			<component id="DC_storeId" type="attribute">
    				<required>false</required>
    			</component>
    			<component id="DC_lang" type="attribute">
    				<required>false</required>
    			</component>
    			<metadatagenerator>com.ibm.commerce.marketing.cache.EMarketingSpotMetaDataGenerator</metadatagenerator>
    		</cache-id>
    </cache-entry>
  3. Include the cache entries that are defined in cachespec.xml file in the following directory:
    • WebSphere Commerce DeveloperWCDE_installdir\samples\dynacache\marketing\
    • WebSphere Commerce EnterpriseWebSphere Commerce - ExpressWebSphere Commerce ProfessionalWC_installdir\samples\dynacache\marketing\
    Note: If you included these cache entries previously, then the only change that is required is including the method getMarketingSpotBehavior as a cache component in the FilterXXXCmdImpl command cache entries.
    <!-- NEW: for e-Marketing Spot caching -->
                <component id="getMarketingSpotBehavior" type="method">
                   <value>1</value>
                </component>
  4. Save and close the cachespec.xml file.
  5. In each e-Marketing Spot JSP snippet, locate the following code:
    <%
       /* Get the e-Marketing Spot name from the request parameters, and decode it in case it has been encoded. */
       String emsName = request.getParameter("emsName");
       if (emsName != null) {
       	emsName = java.net.URLDecoder.decode(emsName, "UTF-8");
    	  request.setAttribute("emsName", emsName);
       }
    Add the following code after the located code.
    	Object DM_marketingSpotBehavior = request.getAttribute("DM_emsBehavior-" + emsName);
      	 if (DM_marketingSpotBehavior != null) 
    	{request.setAttribute("DM_marketingSpotBehavior", DM_marketingSpotBehavior.toString());}
  6. In each e-Marketing Spot JSP snippet, locate the following code:
    <wcf:getData type="com.ibm.commerce.marketing.facade.datatypes.MarketingSpotDataType" var="marketingSpotDatas" expressionBuilder="findByMarketingSpotName">
    
                <%-- the name of the e-Marketing Spot --%>
                <wcf:param name="DM_EmsName" value="${emsName}" />
    Add the following code after the located code.
    <wcf:param name="DM_marketingSpotBehavior" value="${requestScope.DM_marketingSpotBehavior}"/>
  7. In each e-Marketing Spot JSP snippet, locate the end of the <getData> tag:
    </wcf:getData>
    </c:otherwise>
    </c:choose>
    Add the following code after the located code.
    <wcf:eMarketingSpotCache marketingSpotData="${marketingSpotDatas}" contentDependencyName="contentId" catalogEntryDependencyName="productId"  categoryDependencyName="categoryId" />
    By adding this code, the JSP snippet can use the eMarketingSpotCache tag to dynamically determine whether the JSP snippet can be cached. For more information about this tag, see Tag: eMarketingSpotCache.
    Note: Set the values of catalogEntryDependencyName and categoryDependencyName to the names used in the cachespec.xml file invalidation rules for invalidating products and categories.
  8. Save and close each e-Marketing Spot JSP snippet file.
  9. If filtering is enabled to make an action dynamic, then the wc-admin-component.xml file must be configured to set the action as dynamic. For more information about configuring the wc-admin-component.xml file, see Changing properties in the marketing component configuration file (wc-admin-component.xml).
    <!-- E-MARKETING SPOT CACHING BEHAVIOR -->
    	  <!--  Setting to specify that the Display Catalog Entry Action should be considered dynamic. This means the 
    	        marketing engine should evaluate if the catalog entry can be displayed to each individual customer.
    	        For example, you would set this if the catalog entry filter is enabled to remove recommendations
    	        in the customer's shopping cart, purchase history, or based on inventory level. 
    	        Set the value to 1 if the action behavior is dynamic.
    	  -->
      	  <_config:property name="catalogEntryActionBehavior" value="0"/>
    
    	  <!--  Setting to specify that the Display Category Action should be considered dynamic. This means the 
    	        marketing engine should evaluate if the category can be displayed to each individual customer.
    	        Set the value to 1 if the action behavior is dynamic.
    	  -->
      	  <_config:property name="categoryActionBehavior" value="0"/>	
    
    	  <!--  Setting to specify that the Display Content Action should be considered dynamic. This means the 
    	        marketing engine should evaluate if the catalog entry can be displayed to each individual customer.
    	        For example, you would set this if the content filter is enabled to remove recommendations
    	        if the customer is not in a segment associated with a promotion, or is not entitled to the
    	        promoted products. 
    	        Set the value to 1 if the action behavior is dynamic.
    	  -->
      	  <_config:property name="contentActionBehavior" value="0"/>
    The behavior for the corresponding filters is specified in the following table:
    Object Filter Behavior
    Catalog Entry removeIfNoInventory Depends on business requirement – if it evaluates every request, set to dynamic. Otherwise, this filter can rely on a page timeout.
    Catalog Entry removeIfExistInShopcart Dynamic – evaluate for each shopper
    Catalog Entry removeIfExistInPurchaseHistory Dynamic – evaluate for each shopper
    Catalog Entry removeIfPastEndDate Depends on business requirement – if it evaluates every request, set to dynamic. Otherwise, this filter can rely on a page timeout.
    Catalog Entry removeIfNotInCurrentCatalog Static
    Category removeIfNotInCurrentCatalog Static
    Content removeIfPromotionNotAvailable Depends on business requirement – if it evaluates every request, set to dynamic. Otherwise, this filter can rely on a page timeout.
    Content removeIfPromotionBeforeStartDate Depends on business requirement – if it evaluates every request, set to dynamic. Otherwise, this filter can rely on a page timeout.
    Content removeIfMemberNotInPromotionSegment Dynamic – evaluate for every customer
    Content removeIfPromotionNotEntitledCatalogEntryOrCategory Dynamic – evaluate for every customer
  10. Optional: Some optional parameters for an e-Marketing Spot can be configured as follows:
    • If the e-Marketing Spot JSP is included in a servlet cached page, then a static e-Marketing Spot has the JSP consumed by the parent page. If you want to always cache the e-Marketing Spot JSP separately, then define a cacheWithParent parameter with a value of false.
    • If an e-Marketing Spot must be specified static or dynamic without relying on automatic determination, pass the marketingSpotBehavior parameter when you are importing the e-Marketing Spot JSP snippet. Specify a value of 0 for static behavior and a value of 1 for dynamic behavior. The Marketing Manager can also specify whether the marketing content is static or dynamic in the Management Center. For more information, see Creating marketing content to display on store pages.
    • The timeout for the cached fragment is the earliest start or end date of any activity that is scheduled to the e-Marketing Spot after the current time. The timeout is only set if the time is earlier than the current timeout of the page. Usually the timeout is set in the cachespec.xml file, but it can also be specified when you are including the e-Marketing Spot JSP.

    Here is an example on how to set the optional parameters for an e-Marketing Spot. The cacheWithParent parameter is set to cache the ContentAreaESpot.jsp separately from the home page. The marketingSpotBehavior parameter is configured such that the spot is always cached, and does not check the behavior of the activities on the e-Marketing Spot. The pageTimeLimit parameter is configured such that the default time limit is set to one hour.

    <c:import url="${jspStoreDir}Snippets/Marketing/ESpot/ContentAreaESpot.jsp">
                            <c:param name="emsName" value="HomePageRow1Ads" />
                            <c:param name="cacheWithParent" value="false" />
                            <c:param name="marketingSpotBehavior" value="0" />
                            <c:param name="pageTimeLimit" value="3600" />
    </c:import>
  11. If you added database triggers to automatically refresh the Marketing registry after a data propagation, then remove the triggers with WCR+CampaignInitiativeCache invalidation. Clearing the CampaignInitiativeCache registry is no longer required.