Adding key-value pairs to the global cache by using a Mapping node

You can use a Mapping node to add key-value pairs to a map in an embedded cache or a WebSphere® eXtreme Scale grid.

Before you begin

You must complete the following task:
  • Create a graphical data map by using the Graphical Data Mapping editor. For information, see Creating a message map.

About this task

You can use a Cache Put transform in a Mapping node to store data in the global cache.

Interactions with the global cache happen outside the message flow transaction, and are committed immediately. If an error occurs downstream of the node that interacts with the global cache, the cache interactions are not rolled back.

To configure a graphical data map to add data to the global cache, complete the following steps:

Procedure

  1. Open the graphical data map in the Graphical Data Mapping editor.
  2. In the toolbar, click the Cache Put icon (icon) to add a Cache Put transform to the canvas.
  3. Optional: By default, the Cache Put transform adds a new key-value pair to the global cache. You can change the action by selecting one of the following options from the General tab of the Properties for the Cache Put transform:
    • Insert entry into cache (default): Add the key-value pair to the cache.
    • Update entry in cache: Update the value that is associated with the key that is already in the cache.
    • Insert or update entry in cache: If the key already exists in the cache, update the value that is associated with the key. If the key does not already exist in cache, add the key-value pair to the cache.
  4. Provide values for the parameters in the Cache Put transform by completing one of the following steps:
    • Map the input elements to the Cache Put transform.
      Note: You can also select the elements before you click the Cache Put icon. The elements that you select are then automatically mapped to the Cache Put transform.
    • Identify fixed values or user-defined properties to assign to the parameters.

    For example, in the following image, the Value element is mapped to the Cache Put transform.

    The image is described in the surrounding text.

  5. Double-click the Cache Put transform to edit the nested map.
    To edit the nested map, you can also perform any of the following operations:
    • Click the Cache Put link in the Cache Put transform.
    • Click the arrow in the upper right corner of the Cache Put transform.
    • Place the mouse over the Cache Put transform, and click Click here in the pop-up window.

    The output elements of the nested map are the predefined parameters that are required to perform the Cache Put transform. If you mapped elements to the Cache Put transform, the elements are displayed as input elements in the nested map.

  6. Required: Provide values for the Value and Key parameters of the Cache Put transform by using one of the following options:
    Note: The Cache Put transform is marked with an error until a value is provided for the Value and Key parameters.
    • Map an element from the input tree to a parameter. When you map an input element to the Value parameter, you are prompted to apply a mapping cast to redefine the default xs:anySimpleType schema type to a specific schema type (see Casting elements in a message map), so that the global cache entry is created with a specific Java™ Object type. If you do not use a mapping cast on the Value parameter, the Java Object type that is created in the global cache might vary depending on the type of the mapped input element; see Java Object types that are created for each schema input type. Alternatively, you can use an xs:type transform to cast the mapped input element, or assigned value; see Cast type (xs:type).
      Note: If the input element is nillable, use one of the following options:
      • Do not cast the target parameter.
      • Make sure that you cast the target parameter to a String type, which can have a null value.
    • Set a fixed value for a parameter by right-clicking the parameter in the Cache Put transform, clicking Add Assign, and adding the required value in the Properties pane. For more information about the Assign transform, see Assign.
    • Set a value for a parameter by using a user-defined property; see Accessing user-defined properties from a Mapping node.

    For example, in the following image, the content for the Value parameter is provided by mapping an element that is named Value, and the content for the Key parameter is provided by assigning a fixed value.

    The image is described in the surrounding text.

  7. Optional: Map or assign values to the MapName, CacheName, or TimeToLive parameters; for information about valid values for these parameters, see Cache Put.
  8. Optional: Right-click the Cache Put transform and select Cache > Return to implement a nested mapping that is called if the Cache Put transform completes successfully. For more information, see Cache Return.
    Note: You can also add a Cache Return transform by placing the mouse over the Cache Put transform and selecting the Cache Return icon (icon).
  9. Optional: Right-click the Cache Put transform and select Cache > Failure to implement a nested mapping that is called if the Cache Put transform fails. For more information, see Handling global cache exceptions in a graphical data map.
    Note: You can also add a Cache Failure transform by placing the mouse over the Cache Put transform and selecting the Cache Failure icon (icon).
  10. Save the graphical data map.

Results

You added a key-value pair to the global cache.

What to do next

Complete the following tasks:

For more information about the Cache Put transform, see Cache Put.