Specify when data is removed automatically from the global cache.
Create a message flow that contains a JavaCompute node, and create a Java™ file for that node. For detailed instructions, see Accessing the global cache with a JavaCompute node.
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.
MbGlobalMap myMap = MbGlobalMap.getGlobalMap("myMap", new MbGlobalMapSessionPolicy(60));
MbGlobalMapSessionPolicy sessionPol = new MbGlobalMapSessionPolicy(60);
MbGlobalMap myMap = MbGlobalMap.getGlobalMap("myMap", sessionPol);
You can create multiple MbGlobalMap objects in different flows, integration servers, or brokers, 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");
To complete the interaction with the global cache, complete the remaining steps in Accessing the global cache with a JavaCompute node.