cache

cache

Source:

Shared cache namespace. This namespace provides a default cache that can be used to set and retrieve objects that will be persisted between reloads of scripts.

Methods

(static) get(key, defaultSupplieropt) → {*|null}

Source:

Returns the value to which the specified key is mapped

Examples

Get a previously set value with a default value (times = 0)

let counter = cache.get("counter", () => ({ "times": 0 }));
console.log("Count",counter.times++);

Get a previously set object

let counter = cache.get("counter");
if(counter == null){
     counter = {times: 0};
     cache.put("counter", counter);
}
console.log("Count",counter.times++);
Parameters:
Name Type Attributes Description
key string

the key whose associated value is to be returned

defaultSupplier function <optional>

if the specified key is not already associated with a value, this function will return a default value

Returns:

the current object for the supplied key, a default value if defaultSupplier is provided, or null

Type
* | null

(static) put(key, value) → {*|null}

Source:

Associates the specified value with the specified key

Parameters:
Name Type Description
key string

key with which the specified value is to be associated

value *

value to be associated with the specified key

Returns:

the previous value associated with null, or null if there was no mapping for key

Type
* | null

(static) remove(key) → {*|null}

Source:

Removes the mapping for a key from this map if it is present

Parameters:
Name Type Description
key string

key whose mapping is to be removed from the map

Returns:

the previous value associated with key or null if there was no mapping for key

Type
* | null

(static) exists(key) → {boolean}

Source:

Checks the mapping for a key from this map.

Parameters:
Name Type Description
key string

key whose mapping is to be checked in the map

Returns:

whether the key has a mapping

Type
boolean