Skip to content

channelCache.getNumber

Signature: channelCache.getNumber(key, defaultValue*)

Returns: Number numberValue - the value associated with the Number-typed key

Get the Number-typed value associated with the key.

Note

A ClassCastException will be thrown if the cache is not of type Number.

Note

A NullPointerException will be thrown if the cache does not exist and the defaultValue is omitted.

Parameters

Type Name Description Default
String key a unique string used to identify the cached value
Number defaultValue* (optional) the value to return if no value is associated with the key exception is thrown if the key does not exist, and it's impossible to not have a value

Example

// Read a stored Number-typed channel-cache entry. The default value is OPTIONAL:

// (1) With a default -- always safe; the default is returned when the key is unset:
var pageSize = channelCache.getNumber("pageSize", 50); // stored value, or 50 if unset

// (2) Without a default -- returns the stored Number directly, but a missing key throws
//     (the null is unboxed to a primitive), so omit the default only when the key is set:
if (channelCache.checkValueExists("maxRetries")) {
    var maxRetries = channelCache.getNumber("maxRetries"); // the stored Number
}