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
- Enable the store-enhancements feature.
About this task
Procedure
-
Open the
cachespec.xml
cache configuration file in the following directory:- workspace_dir/crs-web/WebContent/WEB-INF/
-
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 istrue
. - The
do-not-cache
property istrue
. - The
metadatagenerator
is specified ascom.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>
- The
-
Include the cache entries that are defined in
cachespec.xml
file in the following directory:- WCDE_installdir\samples\dynacache\marketing\Note: This information only applies to versions prior to HCL Commerce version 9.1.13.0. For HCL Commerce version 9.1.13.0 onwards, the marketing command cache rules are relocated to the cachespec.xml file contained within the InitializationServlet.war file used by the transaction server. If the marketing cache rules were introduced previously by manual customization, they should be removed so that the InitializationServlet rules take precedence.
Note: If you included these cache entries previously, then the only change that is required is including the methodgetMarketingSpotBehavior
as a cache component in theFilterXXXCmdImpl
command cache entries.<!-- NEW: for e-Marketing Spot caching --> <component id="getMarketingSpotBehavior" type="method"> <value>1</value> </component>
- WCDE_installdir\samples\dynacache\marketing\
-
Save and close the
cachespec.xml
file. -
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());}
-
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}"/>
-
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.
By adding this code, the JSP snippet can use the<wcf:eMarketingSpotCache marketingSpotData="${marketingSpotDatas}" contentDependencyName="contentId" catalogEntryDependencyName="productId" categoryDependencyName="categoryId" />
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 ofcatalogEntryDependencyName
andcategoryDependencyName
to the names used in thecachespec.xml
file invalidation rules for invalidating products and categories. - Save and close each e-Marketing Spot JSP snippet file.
-
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 thewc-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 - 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 offalse
. - 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 of0
for static behavior and a value of1
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 theContentAreaESpot.jsp
separately from the home page. ThemarketingSpotBehavior
parameter is configured such that the spot is always cached, and does not check the behavior of the activities on the e-Marketing Spot. ThepageTimeLimit
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>
- 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
-
If you added database triggers to automatically refresh
the Marketing registry after a data propagation, then remove the triggers with
WCR+CampaignInitiativeCache
invalidation. Clearing theCampaignInitiativeCache
registry is no longer required.