Web service caching

The WebSphere Application Server Web service engine provides caching support, so that a Web service request can be cached and the cached response returned in place of subsequent processing; however, this caching support follows the all-or-nothing approach for both the request and the response.

In WebSphere Commerce, with operations represented by commands and the JSP composition service used to compose the result, the Dynacache features of cacheable commands and caching JSP fragments can also be used as a way to cache portions of the request and the response.

Caching a command invoked by a Web service is no different than caching a command invoked as a URL request. In fact, if the command has already been configured to be cached, then the Web service framework will take advantage of that. Similarly, the steps required for caching JSP pages or fragments for Web services are the same as for URL requests.

For JSP responses, consider the following example:

<ShowCatalog xmlns="http://www.openapplications.org/oagis/9" 
  xsi:schemaLocation="http://www.openapplications.org/oagis/9 ../../BODs/Developer/ShowCatalog.xsd" 
  <jsp:include flush="true" page="ApplicationArea.jsp"/>
    <Show recordSetTotal="2" 
  <jsp:include flush="true" page="Show/Catalog.jsp"/>

In this example, two separate JSP pages are included in the response: ApplicationArea.jsp, which can be reused in other Web service responses, and Show/Catalog.jsp.

Within Show/Catalog.jsp, there are three XML blocks, each represented as a JSP fragment:

  <jsp:include flush="true" page="CatalogHeader.jsp"/>
  <jsp:include flush="true" page="ClassificationScheme.jsp"/>
  <jsp:include flush="true" page="CatalogLine.jsp"/>

Either all, some, or none of the JSP fragments might be cacheable. However, for those fragments that are, the caching policy can be created to cache the content, so that the next time the JSP fragment is rendered, the cached version can be used. An example of such a policy is as follows:

  <property name="save-attributes">false</property>

    <component id="catalogId" type="parameter">
    <component id="catalogId" type="parameter">

Within this policy definition, all three fragments are cacheable based on the catalogId parameter found in the request. This catalogId will be either contained in the original service request or returned by the command executed as a result of the service request.

In the preceding example, the first time the response of the service with catalogId of 123 is executed, each JSP will be executed as well.However, the three fragments will also be cached at the same time, so the next time another request is made that includes the same JSP fragments for catalogId of 123, the cached versions of the JSP fragments will be returned.