Validation Cache - ETag

Portlet Specification 2.0 has concept of Validation cache in addition to expiration based cache. Basic idea is Validation-based caching allows portlets to return a validation token together with the markup response and expiration time. The portlet can set the validation token on the RenderResponse or ResourceResponse via the ETAG property from within servlets/JSPs or via the CacheControl setETag method from within the portlet. If no expiration time is set, the content should be viewed by the portlet container as expired

After the content is expired the portlet container should send a render or
serveResource request to the portlet with the validation token (called ETag in HTTP) of the expired content. The portlet can access the validation token provided by the portlet container either via the property ETAG of the RenderRequest or ResourceRequest, or the getETag method of the RenderRequest or ResourceRequest. The portlet can validate if the cached content for the given ETag is still valid or not. If the content is still valid the portlet should not render any output but either set the property USE_CACHED_CONTENT RenderResponse or ResourceResponse and a new expiry time, or setUseCachedContent on the CacheControl of the RenderResponse or
ResourceResponse and set a new expiry time. The portlet should set the validation
token, expiry time or caching scope before writing to the output stream as otherwise
portals / portlet containers may ignore the values.

I tried to modify my ValidationCacheSamplePortlet to see if the ETAG works in either doView() or render method and it seems that both Pluto and WebSphere Portal 6.1.5 ignore the ETAG


public class ValidationCacheSamplePortlet extends GenericPortlet {
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering ValidationCacheSamplePortlet.doView()");
response.setContentType("text/html");
if (request.getETag() != null) { // validation request
System.out.println("ETag is not null, returning from cache");

response.getCacheControl().setExpirationTime(300);
response.getCacheControl().setUseCachedContent(true);
return;
}
System.out.println("ETag is null returning new content");
// create new content with new validation tag
response.getCacheControl().setETag("ABCD");
response.getCacheControl().setExpirationTime(6000);
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(
"/validation.jsp");
rd.include(request, response);
System.out.println("Exiting ValidationCacheSamplePortlet.doView()");

}


public void serveResource(ResourceRequest request, ResourceResponse response)
throws PortletException, IOException {
System.out
.println("Entering ValidationCacheSamplePortlet.serveResource()");
if (request.getETag() != null) { // validation request
System.out.println("ETag is not null, returning resource response from cache");

response.getCacheControl().setExpirationTime(300);
response.getCacheControl().setUseCachedContent(true);
return;
}
System.out.println("ETag is null returning new content");
response.getCacheControl().setETag("1212121ABCD");
response.getCacheControl().setExpirationTime(6000);
response.getWriter().println("Hello from ValidationCacheSamplePortlet.serveResource " + new Date());
System.out
.println("Exiting ValidationCacheSamplePortlet.serveResource()");
}
}


I was hoping that after the first invocation getETag() would return valid value and as a result the control will go to the block that says returning cached content but it did not work, getETag() always returns null

No comments: