Skip to content

sharedCache.setValue

Signature: sharedCache.setValue(key, value, lifespan*, namespace*, global*, persist*)

Returns: void

Set the value associated with the key into an in-memory, thread-safe, cache.

When no namespace is specified, the value is only accessible from inside the channel in which it is set. When a namespace is specified, the value is accessible to all channels in the same zone as the channel in which it is set. When global is set to true, the value is accessible to all channels across all zones.

Note

When global is set to true, namespace becomes a required field.

Parameters

Type Name Description Default
String key a unique string used to identify the cached value
Object value the value that will be stored in the cache
Long lifespan* (optional) time in seconds that the value will live in the cache before it is removed never expires
String namespace* (optional) a unique string used to limit the scope of the value null
Boolean global* (optional) specifies whether or not the value is stored in the global cache false
Boolean persist* (optional) specifies whether or not the value is stored in the database false

Example

// Example: Store a value in the shared cache with a time-to-live (TTL).

// Create a value to cache
var hashMap = new java.util.HashMap();
hashMap.put("Today", new java.util.Date(qie.getSystemTimeMilliseconds()));
hashMap.put("Jon's Bday", qie.deduceDate("2001-09-17"));

// Store the value in the shared cache for 600 seconds
sharedCache.setValue(
    "the map", // key
    hashMap,   // value
    600        // lifespan (seconds)
);

// Retrieve the cached value
var mapRetrieved = sharedCache.getValue("the map");

// Access values from the cached object
var today = mapRetrieved.get("Today");
var birthday = mapRetrieved.get("Jon's Bday");