Skip to content

Shared Cache Object

The Shared Cache object in QIE is a thread-safe cache used to store objects by key for a defined lifespan. Values are held in memory and, when the persist parameter is set to true (or the system-level Shared Cache Settings Default Storage is set to Persisted), are also stored in the database so they survive restarts and are visible to every instance in a cluster. Scope is controlled by the namespace and global parameters:

  • When no namespace is specified, the value is accessible only from the channel in which it was set (the channel ID is used as the implicit namespace).
  • When a namespace is specified and global is false (the default), the value is accessible to all channels in the same zone.
  • When a namespace is specified and global is true, the value is accessible to all channels across all zones, and namespace becomes a required field.

The following Shared Cache object functions are available:

Function Description
Check Value Exists Check for the existence of a Shared Cache value associated with the key. Returns true if the key was found.
Remove All Values Remove all of the shared cache values associated with the namespace. When global is true, namespace is required.
Get Mutex Claim the mutex associated with the mutexId. Returns true if the mutex was successfully obtained.
Release Mutex Release the mutex so it is available for others to obtain. Specify the same namespace/global values that were used when the mutex was obtained.
Get the keySet Get the shared cache keySet associated with the namespace. When global is true, namespace is required.
Get the valueSet Get the shared cache valueSet collection associated with the namespace. When global is true, namespace is required.
Get Value Get an object from the thread-safe cache. When global is true, namespace is required.
Set Value Set the value associated with the key into the thread-safe cache. When global is true, namespace is required.
Remove Value Remove an object from the thread-safe cache. Specify the same namespace and global options that were used when the value was set.

Note

The persist parameter defaults to the system-level Persist Shared Cache setting. When persist is true, values survive restarts; when false, values are held in memory only.

Mutex usage pattern

getMutex blocks until the mutex is claimed (up to the timeout) and releaseMutex returns it. Always release the mutex in a finally block so it is freed even if the protected work throws:

qie.getMutex("rebuild-cache", 15000, 50000);
try {
    // critical section — only one thread/channel runs this at a time
    rebuildLookupTable();
} finally {
    qie.releaseMutex("rebuild-cache");
}

Use the same namespace / global arguments on both calls.