Use this task to configure the DynamicContentProvider interface for cached servlets and
JavaServer Pages (JSP) files.
About this task
A cacheable servlet or JavaServer Pages (JSP) file might contain a state in the response
that does not belong to the fragment for that servlet or JSP. When the state changes, the cached
servlet or JSP is not valid for caching. Use the
com.ibm.websphere.servlet.cache.DynamicContentProvider interface to make the fragment cacheable.
Servlets or JSP files that implement the DynamicContentProvider interface can add user exits in
fragments that are cacheable by calling the addDynamicContentProvider(DCP) method on the wrapper
response object. When the dynamic cache renders the page, it identifies the user exit and calls the
dynamic content provider to add the dynamic content to the rendered page.
Procedure
- Provide an implementation class of the
com.ibm.websphere.servlet.cache.DynamicContentProvider interface.
An example of an
implementation follows:
class DynamicContentProviderImpl implements com.ibm.websphere.servlet.cache.
DynamicContentProvider {
DynamicContentProviderImpl() {}
public void provideDynamicContent(HttpServletRequest request, OutputStream streamWriter)
throws IOException {
String dynamicContent = System.currentTimeMillis();
streamWriter.write(dynamicContent.getBytes());
}
public void provideDynamicContent(HttpServletRequest request, Writer streamWriter)
throws IOException {
String dynamicContent = System.currentTimeMillis();
streamWriter.write(dynamicContent.toCharArray());
}
}
- Add user exits to your servlet or JSP file by calling the addDynamicContentProvider(DCP)
method on the wrapper response object. An example follows:
public class DCPServlet extends CacheTestCase {
public void performTest(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
out.println("Testing the DCP feature begin "+System.currentTimeMillis());
DynamicContentProvider dcp = new DynamicContentProviderImpl();
ServletCacheResponse scr = (ServletCacheResponse)(response);
scr.addDynamicContentProvider(dcp);
out.println("Testing the DCP feature end"+System.currentTimeMillis());
}
}
What to do next
See Improving performance with the dynamic cache service for more information about the other tasks that
you can perform with the dynamic cache.