Thursday, 23 October 2014

When JSP coding turns Dyncache into a nightmare



The two code samples below looks very similar and they both work fine when tested in a local development environment without caching enabled. But once WebSphere Dynacache is enabled, the first code sample will start causing weird effects on front end. To be more specific, on first access to the page, the content that is generated by CategoryRecommendation.jsp will render correctly without problems, but subsequent access (e.g. page refresh) which is supposed to fetch content from cache, the content will suddenly disappear.

Whenever you see this issue, first thing to look for is your JSP flush which needs to be positioned exactly before and after c:import without anything in-between.

That is one of the reasons I personally prefer to use jsp:import as you can pass flush as an attribute to the tag and you don't have to worry about doing such a mistake.

Code sample 1

<%out.flush();%>
<c:import var="fscontent" url="/ArgSharedStore/Widgets/Tmpl/ESpot/CategoryRecommendation/CategoryRecommendation.jsp">
<c:param name="emsName" value="${spotName}" />
<c:param name="cacheWithParent" value="false" />
<c:param name="catalogId" value="${catalogId}" />
<c:param name="align" value="${align}" />
</c:import>
<c:out value="${fscontent}" escapeXml="false" />
<%out.flush();%>



Code sample 2

<%out.flush();%>
<c:import var="fscontent" url="/ArgSharedStore/Widgets/Tmpl/ESpot/CategoryRecommendation/CategoryRecommendation.jsp">
<c:param name="emsName" value="${spotName}" />
<c:param name="cacheWithParent" value="false" />
<c:param name="catalogId" value="${catalogId}" />
<c:param name="align" value="${align}" />
</c:import>
<%out.flush();%>

<c:out value="${fscontent}" escapeXml="false" />


No comments:

Post a Comment