Specifying how long data remains in the global cache by using the JavaCompute node
Specify when data is removed automatically from the global cache.
Before you begin
Create a message flow that contains a Mapping node or a JavaCompute node that is configured to access the global cache. For more information, see Accessing the global cache by using a Mapping node or Accessing the global cache by using a JavaCompute node.
About this task
When you get an MbGlobalMap object, you can specify how long the data remains in the global cache before it is removed automatically. This time is known as the time to live and is counted from when that map entry is last updated. The value applies to all cache entries that are created by using that MbGlobalMap object in that instance of the message flow. Data that is already in the map that you specify, or that is created by another MbGlobalMap object, is not affected by the time to live value.
By default, the time to live is set to zero so that the data is never removed. To set a specific time to live, create a session policy, which you can reference from the MbGlobalMap object.
You can create multiple MbGlobalMap objects in different flows, integration servers, or integration nodes, all resolving to the same map in the global cache, but with different time to live values. However, you must structure the code in a specific way when you want to put multiple cache entries, with different time to live values, into the same map in the same message flow.
MbGlobalMap m1 = MbGlobalMap.getGlobalMap("myMap", new MbGlobalMapSessionPolicy(60));
MbGlobalMap m2 = MbGlobalMap.getGlobalMap("myMap", new MbGlobalMapSessionPolicy(40));
MbGlobalMap m3 = MbGlobalMap.getGlobalMap("myMap", new MbGlobalMapSessionPolicy(20));
m1.put("k1","v1");
m2.put("k2","v2");
m3.put("k3","v3");
MbGlobalMap m1 = MbGlobalMap.getGlobalMap("myMap", new MbGlobalMapSessionPolicy(60));
m1.put("k1","v1");
m1 = MbGlobalMap.getGlobalMap("myMap", new MbGlobalMapSessionPolicy(40));
m1.put("k2","v2");
m1 = MbGlobalMap.getGlobalMap("myMap", new MbGlobalMapSessionPolicy(20));
m1.put("k3","v3");