Skip to content

sharedCache.getValue

Signature: sharedCache.getValue(key, namespace*, global*, persist*)

Returns: Object value - the object retrieved from cache

Get an object from the thread-safe cache.

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

Note

When global is set to true and no namespace is supplied, one shared global namespace is used, which every channel in every zone can read and write. Supply a namespace to keep global values apart.

Note

namespace is optional. When not specified, {channel ID} scopes the value to the channel running the script, so no other channel can see it.

Note

persist is optional. When not specified, {system default} is the Default Storage setting on the System Config page under Shared Cache Settings.

Parameters

Type Name Description Default
String key a unique string used to identify the cached value
String namespace* (optional) a unique string used to limit the scope of the value {channel ID}
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 {system default}

Example

// Example: Retrieve a value from the shared cache by key.

// Populate the shared 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"));

sharedCache.setValue(
    "the map", // key
    hashMap,   // value
    600        // TTL (seconds)
);

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

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