Skip to content

sharedCache.checkValueExists

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

Returns: Boolean exists - true if a value is found, false if a value is not found

Check for the existence of a Shared Cache value associated with the key, a result of true means the key was found.

When no namespace is specified, only keys set in the current channel are searched. When a namespace is specified, all channels in the same zone as the channel in which the key was set are searched. When global is set to true, all channels across all zones are searched.

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 search Channel ID
Boolean global* (optional) specifies whether or not the key is searched for in the global cache false
Boolean persist* (optional) specifies whether or not the key is stored in the database false

Example

// Example: Check whether a value exists in the shared cache.

// Define a cache key and store a value
var myKey = "this is the key";
sharedCache.setValue(myKey, "The secret lies with Charlotte.");

// Check if the key exists before retrieving the value
var exists = sharedCache.checkValueExists(myKey); // true

if (exists) {
    var cachedValue = sharedCache.getValue(myKey); // "The secret lies with Charlotte."
}