Skip to content

Get

Retrieves a cached value by its key, if it exists.

1
$Cache.Get(key: string):( T | null )

Parameters

string key
    The key of the value to retrieve.

Returns

The cached value if found; otherwise, null.

Remarks

The key name can include a ":" qualifier if needed. Script keys are internally prefixed with Scripting:, isolating this surface from callers that use the underlying cache directly.

Values are JSON-serialized. Objects and arrays are returned as fresh script objects; recognized date-time strings are returned as DateTimeOffset values.

Examples

Read a value from the cache or load it

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
var key = 'Customer:' + $Xml.Evaluate('CustomerId');
var customer = $Cache.Get(key);

if (customer == null) {
    customer = $Rest.Create('https://api.example.com')
        .Request('customers/' + $Xml.Evaluate('CustomerId'))
        .Get()
        .ToJson();
    $Cache.Set(key, customer, '00:10:00');
}

$Xml.SetValue('CustomerName', customer.name);

See Also