Using the DynamicContentProvider interface for dynamic cache

Use this task to configure the DynamicContentProvider interface for cached servlets and JavaServer Pages (JSP) files.

Before you begin

The dynamic cache service should be enabled and you should be using servlet caching. See 동적 캐시 서비스 사용 and 서블릿 캐싱 구성 for more information.

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

  1. 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());
    				}
    			}
  2. 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 태스크 개요: 동적 캐시 서비스를 사용하여 성능 개선 for more information about the other tasks that you can perform with the dynamic cache.

주제 유형을 표시하는 아이콘 태스크 주제



시간소인 아이콘 마지막 업데이트 날짜: July 9, 2016 6:10
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tdyn_dynamiccp
파일 이름:tdyn_dynamiccp.html