Home


Component sub-element

Use the component sub-element to generate a portion of the cache ID. The component sub-element consists of the following attributes and elements:

Attributes

Id

Type

Ignore-value

Elements

Index

Method

Field

Required

Value

Not-value

Use the ID attribute to identify the component.

Use the type attribute to identify the type of component. Table | -4 lists the values for type.

Table 6-4 Cachespec.xml component types

Type Object Meaning
method Command Calls the indicated method on the command or object.
field Command Retrieves the named field in the command or object.
parameter Servlet Retrieves the named parameter value from the request object.
parameter-list Servlet Retrieves a list of values for the named parameter.
session Servlet Retrieves the named value from the HTTP session.
cookie Servlet Retrieves the named cookie value.
attribute Servlet Retrieves the named request attribute.
header Servlet and Web service Retrieves the named request header.
pathInfo Servlet Retrieves the pathInfo element from the request. Dynacache pulls out the pathinfo using:
(String) request.getAttribute("javax.servlet.include.path_info");
servletpath Servlet Retrieves the servlet path. Dynacache pulls out the servlet path using:
(String) request.getAttribute("javax.servlet.include.servlet_path");
locale Servlet Retrieves the request locale.
requestType Servlet Retrieves the HTTP request method from the request.
tiles_attribute Servlet Retrieves the value of an attribute from a tile.
SOAPEnvelope Web service and client Retrieves the SOAPEnvelope element from a Web services request. An ID attribute of Hash uses a Hash of the SOAPEnvelope element, while Literal uses the SOAPEnvelope element as received.
SOAPAction Web service Retrieves the SOAPAction header, if available, for a Web services request.
serviceOperation Web service Retrieves the service operation for a Web services request.
serviceOperation Parameter Web service Retrieves the specified parameter from a Web services request.
operation Web services client cache Indicates an operation type in the Web Services Description Language (WSDL) file. The id attribute is ignored and the value is the operation or method name. If the namespace of the operation is specified, format the value as namespaceOfOperation:nameOfOperation.
part Web services client cache Indicates an input message part in the WSDL file or a request parameter. Its ID attribute is the part or parameter name, and the value is the part or parameter value.
SOAPHeaderEntry Web services client cache Retrieves special information in the Simple Object Access Protocol (SOAP) header of the Web services request. The id attribute specifies the name of the entry. In addition, the entry of the SOAP header in the SOAP request must have the actor attribute, which contains com.ibm.websphere.cache.

For example:

<soapenv:Header>
<getQuote soapenv:actor="com.ibm.websphere.cache">IBM</getQuote>
</soapenv:Header>
sessionID Servlet Retrieves the HTTP session ID.


Ignore-value

Use the ignore-value attribute to specify whether or not to use the value that is returned by this component in cache ID formation. This attribute is optional, with a default value of false. If the value is true, only the ID of the component is used when creating a cache ID, or no output is used when creating a dependency or invalidation ID.


Index element

Use the index element with the previous component type to add the value of the element at the specified index position in the collection or array to the ID that is being created.

Example 6-22 Use of Index element

<cache-entry>
  <class>servlet</class>
  <name>xxx.jsp</name>
  <cache-id>
    .
    .
      <component id="users" type="attribute">
        <required>true</required>
        <index>1</index>
      </component>
    .
    .
  </cache-id>
  <dependency-id>dep
    <component id="users" type="attribute" multipleIDs="true">
      <required>true</required>
    </component>
  </dependency-id>
</cache-entry>

The previous cache policy generates the following component to use in the cache ID: users: b. Use the <method> element to call a void method on a returned object.


Method: Calling Java methods

Use the method element to call a method on a returned object. Method and field objects are infinitely nestable in any combination. The method must be public and is not valid for edge-cacheable components. For example:

<component id="getUser" type="method"><method>getUserInfo
<method>getName</method></method></component>

This method is equivalent to getUser().getUserInfo().getName().

Component types attribute, method, or field can return an object. When the object returned is a collection or array, the index ID is created with a comma separated list of the elements in the collection or array. For example, if the request attribute users returns an array [a, b] and the cache entry is defined like Example | -23, then the cache ID will contain the string users: a,b. The dependency ID will be dep: a,b.

Example 6-23 cachespec.xml where attribute users returns an array [a, b]

<cache-entry>
  <class>servlet</class>
  <name>xxx.jsp</name>
  <cache-id>
    .
    .
    <component id="users" type="attribute">
      <required>true</required>
    </component>
    .
    .
  </cache-id>
  <dependency-id>dep
    <component id="users" type="attribute">
      <required>true</required>
    </component>
  </dependency-id>
</cache-entry>

Use the multipleIDs attribute with the component types to specify and generate multiple dependency IDs (or invalidation IDs), based on the items in the collection or array (see Example | -24).

Example 6-24 Using multipleID attribute in generating a dependency ID

<cache-entry>
  <class>servlet</class>
  <name>xxx.jsp</name>
  <cache-id>
    ...
        <component id="users" type="attribute">
        <required>true</required>
      </component>
    ...
  </cache-id>
  <dependency-id>dep
    <component id="users" type="attribute" multipleIDs="true">
      <required>true</required>
    </component>
  </dependency-id>
</cache-entry>

Based on Example | -24, the cache policy will generate the following dependency IDs:

dep:a,b 
dep:a 
dep:b 


Field element

Use the field element to access a field in a returned object. Method and field objects are infinitely nestable in any combination. The field must be public. This field is not valid for edge-cacheable components. For example:

<component id="getUser" type="method"><method>getUserInfo
<field>name</field></method></component>

This method is equivalent to the getUser().getUserInfo().name method.


Required element

Use the required element to specify whether or not this component must return a non-null value for this cache ID to represent a valid cache. If set to true, this component must return a non-null value for this cache ID to represent a valid cache ID. If set to false, the default, a non-null value is used in the formation of the cache ID and a null value means that this component is not used at all in the ID formation. For example:

<required>true</required>


Value element

Use the value element to specify values that must match to use this component in cache ID formation. For example:

Example 6-25 Use of value

<component id="getColor" type="method">
<required>true</required>
<value>blue</value> 
<value>red</value> 

</component>


Not-value

Use the not-value element to specify values that must not match in order to use the component in cache ID formation. This method is similar to value element, but instead prescribes the defined values from caching. You can use multiple not-value elements when more than one value that is not valid exists. This is shown in Example | -26.

Example 6-26 Use of not-value

<component id="getColor" type="method">
<required>true</required>
<not-value>blue</not-value>
<not-value>red</not-value>
</component>

The component sub-element has either a method and a field element, a value element, or a not-value element. The method and field elements apply to commands only. The following example illustrates the attributes of a component sub-element:

<component id="isValid" type="method" ignore-value="true"><component>

+

Search Tips   |   Advanced Search