- You have two JSPs, a parent JSP called parent.jsp and a child which it dynamically includes a child JSP called child.jsp.
- Child JSP requires one parameter to function properly and you need this parameter to be passed with user request to generate some dynamic content that doesn't depend on cache. Let's assume this parameter is called action1.
- You want to cache the parent but you don't wish to cache the child/
- The cachespec.xml is defined something as shown below.
<cache-entry><class>servlet</class><name>/StorefrontAssetStore/parent.jsp</name><property name="do-not-consume">true</property><property name="save-attributes">false</property><property name="consume-subfragments">true</property><cache-id><component id="someparam" type="parameter"><required>true</required></component></cache-id></cache-entry>
<cache-entry><class>servlet</class><name>/StorefrontAssetStore/child.jsp</name><property name="do-not-consume">true</property><property name="do-not-cache">true</property>
<property name="save-attributes">false</property><property name="consume-subfragments">true</property><cache-id><component id="action1" type="parameter"><required>true</required></component></cache-id></cache-entry>
Now, when you are developing the JSPs, you will most probably dynamically include the child from the parent as follows:
<jsp:include page="child.jsp" flush="true"><jsp:param name="action1" value="${param.action1}"/>
</jsp:include>
So question is, will this work as intended ? parent.jsp cached once and child.jsp is dynamically invoked with every request with a fresh value for action1 ?
Unfortunately, this will not happen and despite the child JSP is not cached, it will behave as if it is cached.
Why ?
Things will be more clear, if you opened WebSphere Cache monitor and checked how parent JSP is cached in first place, you will notice something as the below in its cache content:
[include: /StorefrontAssetStore/child.jsp?action1=somevalue]
Which means, whenever parent JSP is accessed from cache, it will dynamically call child JSP but within all calls, it is always passing one cached value which is <somevalue>
So how to get over this ?
Simply, your parent JSP needs to look something as below:
<jsp:include page="child.jsp" flush="true"/>
and within child JSP make sure you always access action1 using param.action1. This will ensure that child JSP is completely free from cache content and able to pickup parameters properly each time from the request stream and do something different each time.
No comments:
Post a Comment