ETag
smart_umesh_123 Feb 4, 2011 5:06 AMI tried the response.getCacheControl().setUseCachedContent(true). but it does not work.
Here is my portlet class
-
package com.mycompany.frs.portlet;
public class CacheDemo extends GenericPortlet
{
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
{
System.out.println("**---- " + this.getClass().getName() + "'s doView is started");
if (request.getETag() != null)
{
if (request.getETag().startsWith("MY_ETAG"))
{
System.out.println("/////// MARKUP IS VALID");
response.getCacheControl().setExpirationTime(30);
response.getCacheControl().setUseCachedContent(true);
return;
}
}
else
{
response.getCacheControl().setETag("MY_ETAG" + (new Date()));
response.getCacheControl().setExpirationTime(30);
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/CacheDemo.jsp");
dispatcher.include(request, response);
}
}
}
portlet.xml =
<portlet>
<description>CacheDemo</description>
<portlet-name>CacheDemo</portlet-name>
<display-name>CacheDemo</display-name>
<portlet-class>com.mycompany.frs.portlet.CacheDemo</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>EDIT</portlet-mode>
</supports>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>HELP</portlet-mode>
</supports>
<portlet-info>
<title>CacheDemo</title>
<short-title>CacheDemo</short-title>
</portlet-info>
<expiration-cache>30</expiration-cache>
</portlet>
CacheDemo.jsp
<%@page import="java.util.Date"%>
<H1> Hello Friends, I am cached contents !! </H1>
<%= new Date() %>
Platform : Jboss Portal 2.7.2
Problem :
When I refresh the page after 30 seconds, the portlet vanishes from the Portal page.
When I again refresh the page immediately, the portlet appears, with the cached contents. That is, it does not show the current date
-----------------
Thanks
Umesh Pathak