Store

Store

The class whose instance is returned when using .create. You can access the internal properties and interact with the store with its methods.

Constructor

new Store()

Refer to create to get instance of this class.

Properties:
Name Type Description
map Map

Internal storage, values are not stored as strings but as their native objects

props Properties

AppsScripts' PropertiesService instance

cache Cache

AppsScripts' CacheService instance

Source:
See:
Example
const store = ObjectStore.create('script');
// load it at execution start time
store.load();
store.set('key1', 'key1');
store.set('key2', 'key2');
store.persist();

Methods

get(key, skipCacheopt) → {any}

Retrieve the value stored at key, return null if not present

Parameters:
Name Type Attributes Default Description
key String

The key of which to return

skipCache Boolean <optional>
true

If true (the default), don't interact with the cache service for this call

Source:

getAll() → {Object}

Iterates over this.getKeys() and returns each key in an object

Source:

getKeys() → {Array.<String>}

Returns the keys that have been stored externally in Properties

Source:

load()

Download from the PropertyStore and store locally

Source:

persist(skipCacheopt)

Take what has been stored in .map and update the property store

Parameters:
Name Type Attributes Default Description
skipCache Boolean <optional>
true

If true (the default), don't interact with the cache service for this call

Source:

remove(keyopt)

Parameters:
Name Type Attributes Description
key String <optional>

The key to remove

Source:
Throws:

if key is not a string

Type
TypeError

removeAll(keysopt)

Removes keys and values from external stores. Since the cache requires a list of keys explicitely given, keys parameter is available to specific which ones to delete from the cache. The props are deleted in its entirety. The keys param probably only needs to be set in testing conditions.

Parameters:
Name Type Attributes Default Description
keys Array.<String> <optional>
null

The keys to remove from the cache (note that all keys are removed from properties, irregardless of the value of this parameter)

Source:

set(key, value, skipCacheopt)

Stores the value at key. If in auto mode, also stores in cache and properties

Parameters:
Name Type Attributes Default Description
key String

The identifier, must be a string

value String

The data to be stored at key.

skipCache Boolean <optional>
true

If true (the default), don't interact with the cache service for this call

Source:
Throws:
  • Type error if key is not a string

    Type
    TypeError
  • Type error if value is not a string, and it attempts to write to external stores

    Type
    TypeError

setProperties(properties, skipCacheopt)

Calls .setProperties with properties after iterating through, serializing, and storing in local map

Parameters:
Name Type Attributes Default Description
properties Object

object representing key/values

skipCache Boolean <optional>
true

If true (the default), don't interact with the cache service for this call

Source: